annotate test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java @ 341:75c452fdd76a

Merging state not detected when there's no conflicts to resolve (no merge/state file)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 17 Nov 2011 07:04:58 +0100
parents 694ebabb5cb3
children 5f9073eabf06
rev   line source
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 package org.tmatesoft.hg.test;
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2
324
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
3 import static org.tmatesoft.hg.repo.HgRepository.TIP;
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
4
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
5 import java.io.File;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
6 import java.util.ArrayList;
256
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
7 import java.util.Arrays;
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
8 import java.util.HashMap;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
9 import java.util.LinkedList;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
10 import java.util.List;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
11 import java.util.Map;
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12
324
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
13 import org.junit.Assert;
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 268
diff changeset
14 import org.tmatesoft.hg.core.HgBadStateException;
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
15 import org.tmatesoft.hg.core.HgChangeset;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
16 import org.tmatesoft.hg.core.HgChangesetHandler;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
17 import org.tmatesoft.hg.core.HgException;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
18 import org.tmatesoft.hg.core.HgLogCommand;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
19 import org.tmatesoft.hg.core.Nodeid;
326
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
20 import org.tmatesoft.hg.internal.IntMap;
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
21 import org.tmatesoft.hg.repo.HgChangelog;
326
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
22 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
23 import org.tmatesoft.hg.repo.HgDataFile;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
24 import org.tmatesoft.hg.repo.HgLookup;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
25 import org.tmatesoft.hg.repo.HgManifest;
326
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
26 import org.tmatesoft.hg.repo.HgManifest.Flags;
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
27 import org.tmatesoft.hg.repo.HgRepository;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
28 import org.tmatesoft.hg.repo.HgTags;
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import org.tmatesoft.hg.repo.HgTags.TagInfo;
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
30 import org.tmatesoft.hg.util.CancelledException;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
31 import org.tmatesoft.hg.util.Path;
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 /**
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 * @author Marc Strapetz
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 */
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 public class MapTagsToFileRevisions {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 // Static =================================================================
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
40 public static void main(String[] args) throws Exception {
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
41 MapTagsToFileRevisions m = new MapTagsToFileRevisions();
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
42 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
43 m.measurePatchAffectsArbitraryRevisionRead();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
44 // m.collectTagsPerFile();
307
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
45 // m.manifestWalk();
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
46 // m.changelogWalk();
324
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
47 // m.revisionMap();
326
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
48 // m.buildFile2ChangelogRevisionMap();
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
49 m = null;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
50 System.gc();
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
51 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
52 }
324
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
53
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
54
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
55 // revision == 2406 - 5 ms per run (baseRevision == 2406)
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
56 // revision == 2405 - 69 ms per run (baseRevision == 1403)
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
57 private void measurePatchAffectsArbitraryRevisionRead() throws Exception {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
58 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
59 final DoNothingManifestInspector insp = new DoNothingManifestInspector();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
60 final int revision = 2405;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
61 // warm-up.
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
62 repository.getManifest().walk(revision, revision, insp);
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
63 final int runs = 10;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
64 final long start = System.nanoTime();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
65 for (int i = 0; i < runs; i++) {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
66 repository.getManifest().walk(revision, revision, insp);
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
67 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
68 final long end = System.nanoTime();
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
69 System.out.printf("%d ms per run\n", (end - start)/ (runs*1000000));
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
70 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
71
324
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
72 /*
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
73 * .hgtags, 261 revisions
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
74 * Approach 1: total 83, init: 0, iteration: 82
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
75 * Approach 2: total 225, init: 206, iteration: 19
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
76 * README, 465 revisions
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
77 * Approach 1: total 162, init: 0, iteration: 161
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
78 * Approach 2: total 231, init: 198, iteration: 32
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
79 * configure.in, 1109 revisions
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
80 * Approach 1: total 409, init: 1, iteration: 407
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
81 * Approach 2: total 277, init: 203, iteration: 74
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
82 */
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
83 private void buildFile2ChangelogRevisionMap() throws Exception {
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
84 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
85 final HgChangelog clog = repository.getChangelog();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
86 final HgDataFile fileNode = repository.getFileNode("configure.in");
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
87 // warm-up
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
88 HgChangelog.RevisionMap clogMap = clog.new RevisionMap().init();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
89 HgDataFile.RevisionMap fileMap = fileNode.new RevisionMap().init();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
90 //
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
91 final int latestRevision = fileNode.getLastRevision();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
92 //
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
93 final long start_1 = System.nanoTime();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
94 fileMap = fileNode.new RevisionMap().init();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
95 final long start_1a = System.nanoTime();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
96 final Map<Nodeid, Nodeid> changesetToNodeid_1 = new HashMap<Nodeid, Nodeid>();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
97 for (int revision = 0; revision <= latestRevision; revision++) {
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
98 final Nodeid nodeId = fileMap.revision(revision);
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
99 // final Nodeid changesetId = fileNode.getChangesetRevision(nodeId);
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
100 int localCset = fileNode.getChangesetLocalRevision(revision);
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
101 final Nodeid changesetId = clog.getRevision(localCset);
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
102 changesetToNodeid_1.put(changesetId, nodeId);
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
103 }
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
104 final long end_1 = System.nanoTime();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
105 //
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
106 final long start_2 = System.nanoTime();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
107 clogMap = clog.new RevisionMap().init();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
108 fileMap = fileNode.new RevisionMap().init();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
109 final Map<Nodeid, Nodeid> changesetToNodeid_2 = new HashMap<Nodeid, Nodeid>();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
110 final long start_2a = System.nanoTime();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
111 for (int revision = 0; revision <= latestRevision; revision++) {
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
112 Nodeid nidFile = fileMap.revision(revision);
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
113 int localCset = fileNode.getChangesetLocalRevision(revision);
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
114 Nodeid nidCset = clogMap.revision(localCset);
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
115 changesetToNodeid_2.put(nidCset, nidFile);
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
116 }
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
117 final long end_2 = System.nanoTime();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
118 Assert.assertEquals(changesetToNodeid_1, changesetToNodeid_2);
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
119 //
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
120 final long start_3 = System.nanoTime();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
121 final Map<Nodeid, Nodeid> changesetToNodeid_3 = new HashMap<Nodeid, Nodeid>();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
122 fileNode.walk(0, TIP, new HgDataFile.RevisionInspector() {
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
123
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
124 public void next(int localRevision, Nodeid revision, int linkedRevision) {
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
125 changesetToNodeid_3.put(clog.getRevision(linkedRevision), revision);
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
126 }
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
127 });
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
128 final long end_3 = System.nanoTime();
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
129 Assert.assertEquals(changesetToNodeid_1, changesetToNodeid_3);
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
130 System.out.printf("Approach 1: total %d, init: %d, iteration: %d\n", (end_1 - start_1)/1000000, (start_1a - start_1)/1000000, (end_1 - start_1a)/1000000);
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
131 System.out.printf("Approach 2: total %d, init: %d, iteration: %d\n", (end_2 - start_2)/1000000, (start_2a - start_2)/1000000, (end_2 - start_2a)/1000000);
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
132 System.out.printf("Approach 3: total %d\n", (end_3 - start_3)/1000000);
283b294d1079 Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
133 }
263
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
134
307
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
135 /*
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
136 * Each 5000 revisions from cpython, total 15 revisions
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
137 * Direct clog.getLocalRevision: ~260 ms
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
138 * RevisionMap.localRevision: ~265 ms (almost 100% in #init())
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
139 * each 1000'th revision, total 71 revision: 1 230 vs 270
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
140 * each 2000'th revision, total 36 revision: 620 vs 270
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
141 * each 3000'th revision, total 24 revision: 410 vs 275
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
142 */
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
143 private void revisionMap() throws Exception {
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
144 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
145 final HgChangelog clog = repository.getChangelog();
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
146 ArrayList<Nodeid> revisions = new ArrayList<Nodeid>();
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
147 final int step = 5000;
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
148 for (int i = 0, top = clog.getLastRevision(); i < top; i += step) {
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
149 revisions.add(clog.getRevision(i));
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
150 }
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
151 final long s1 = System.nanoTime();
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
152 for (Nodeid n : revisions) {
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
153 int r = clog.getLocalRevision(n);
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
154 if (r % step != 0) {
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
155 throw new IllegalStateException(Integer.toString(r));
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
156 }
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
157 }
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
158 System.out.printf("Direct lookup of %d revisions took %,d ns\n", revisions.size(), System.nanoTime() - s1);
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
159 HgChangelog.RevisionMap rmap = clog.new RevisionMap();
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
160 final long s2 = System.nanoTime();
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
161 rmap.init();
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
162 final long s3 = System.nanoTime();
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
163 for (Nodeid n : revisions) {
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
164 int r = rmap.localRevision(n);
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
165 if (r % step != 0) {
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
166 throw new IllegalStateException(Integer.toString(r));
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
167 }
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
168 }
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
169 System.out.printf("RevisionMap time: %d ms, of that init() %,d ns\n", (System.nanoTime() - s2) / 1000000, s3 - s2);
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
170 }
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
171
263
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
172 private void changelogWalk() throws Exception {
307
2f2ab5c27f41 Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 304
diff changeset
173 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
263
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
174 final long start = System.currentTimeMillis();
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
175 repository.getChangelog().all(new HgChangelog.Inspector() {
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
176 public int xx = 0;
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
177
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
178 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
179 if (xx+revisionNumber < 0) {
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
180 System.out.println(xx);
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
181 System.out.println(revisionNumber);
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
182 }
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
183 xx += revisionNumber;
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
184 }
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
185 });
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
186 // cpython: 17 seconds, mem 132,9 -> 129,0 -> 131,7
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
187 // cpyhton: 13 seconds. Of that, cumulative Patch.apply takes 8.8 seconds, RevlogStream.Inspector.next - 1.8
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
188 System.out.printf("Total time: %d ms\n", System.currentTimeMillis() - start);
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
189 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
190 }
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
191
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
192 private void manifestWalk() throws Exception {
268
c5980f287cc4 Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 263
diff changeset
193 System.out.println(System.getProperty("java.version"));
263
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
194 final long start = System.currentTimeMillis();
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
195 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
196 repository.getManifest().walk(0, 10000, new DoNothingManifestInspector());
263
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
197 // cpython: 1,1 sec for 0..1000, 43 sec for 0..10000, 115 sec for 0..20000 (Pool with HashMap)
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
198 // 2,4 sec for 1000..2000
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
199 // cpython -r 1000: 484 files, -r 2000: 1015 files. Iteration 1000..2000; fnamePool.size:1019 nodeidPool.size:2989
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
200 // nodeidPool for two subsequent revisions only: 840. 37 sec for 0..10000. 99 sec for 0..20k
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
201 // 0..10000 fnamePool: hits:15989152, misses:3020
268
c5980f287cc4 Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 263
diff changeset
202 //
c5980f287cc4 Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 263
diff changeset
203 // With Pool<StringProxy> for fname and flags, Nodeid's ascii2bin through local array, overall byte[] iteration,
c5980f287cc4 Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 263
diff changeset
204 // 0..10k is 34 seconds now
304
85b8efde5586 Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
205 // Another run, 23 seconds now, seems nothing has been changed. Switched to Pool2 with DirectHashSet: 22,5 seconds
263
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
206 System.out.printf("Total time: %d ms\n", System.currentTimeMillis() - start);
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
207 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
208 }
326
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
209
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
210 private int[] collectLocalTagRevisions(HgChangelog.RevisionMap clogrmap, TagInfo[] allTags, IntMap<List<TagInfo>> tagLocalRev2TagInfo) {
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
211 int[] tagLocalRevs = new int[allTags.length];
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
212 int x = 0;
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
213 for (int i = 0; i < allTags.length; i++) {
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
214 final Nodeid tagRevision = allTags[i].revision();
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
215 final int tagLocalRev = clogrmap.localRevision(tagRevision);
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
216 if (tagLocalRev != HgRepository.BAD_REVISION) {
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
217 tagLocalRevs[x++] = tagLocalRev;
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
218 List<TagInfo> tagsAssociatedWithRevision = tagLocalRev2TagInfo.get(tagLocalRev);
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
219 if (tagsAssociatedWithRevision == null) {
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
220 tagLocalRev2TagInfo.put(tagLocalRev, tagsAssociatedWithRevision = new LinkedList<TagInfo>());
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
221 }
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
222 tagsAssociatedWithRevision.add(allTags[i]);
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
223 }
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
224 }
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
225 if (x != allTags.length) {
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
226 // some tags were removed (recorded Nodeid.NULL tagname)
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
227 int[] copy = new int[x];
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
228 System.arraycopy(tagLocalRevs, 0, copy, 0, x);
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
229 tagLocalRevs = copy;
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
230 }
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
231 return tagLocalRevs;
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
232 }
263
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
233
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 259
diff changeset
234 private void collectTagsPerFile() throws HgException, CancelledException {
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
235 final long start = System.currentTimeMillis();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
236 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
237 final HgTags tags = repository.getTags();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
238 //
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
239 // build cache
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
240 //
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
241 final TagInfo[] allTags = new TagInfo[tags.getTags().size()];
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
242 tags.getTags().values().toArray(allTags);
326
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
243 // effective translation of changeset revisions to their local indexes
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
244 final HgChangelog.RevisionMap clogrmap = repository.getChangelog().new RevisionMap().init();
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
245 // map to look up tag by changeset local number
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
246 final IntMap<List<TagInfo>> tagLocalRev2TagInfo = new IntMap<List<TagInfo>>(allTags.length);
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
247 System.out.printf("Collecting manifests for %d tags\n", allTags.length);
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
248 final int[] tagLocalRevs = collectLocalTagRevisions(clogrmap, allTags, tagLocalRev2TagInfo);
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
249 System.out.printf("Prepared %d tag revisions to analyze: %d ms\n", tagLocalRevs.length, System.currentTimeMillis() - start);
326
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
250
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
251 final Path targetPath = Path.create("README");
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
252 //
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
253 collectTagsPerFile_Approach_1(clogrmap, tagLocalRevs, allTags, targetPath);
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
254 System.out.printf("Total time: %d ms\n", System.currentTimeMillis() - start);
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
255
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
256 System.out.println("\nApproach 2");
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
257 collectTagsPerFile_Approach_2(repository, tagLocalRevs, tagLocalRev2TagInfo, allTags, targetPath);
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
258 }
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
259
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
260 // Approach 1. Build map with all files, their revisions and corresponding tags
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
261 //
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
262 private void collectTagsPerFile_Approach_1(final HgChangelog.RevisionMap clogrmap, final int[] tagLocalRevs, final TagInfo[] allTags, Path targetPath) {
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
263 HgRepository repository = clogrmap.getRepo();
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
264 final long start = System.currentTimeMillis();
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
265 // file2rev2tag value is array of revisions, always of allTags.length. Revision index in the array
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
266 // is index of corresponding TagInfo in allTags;
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 268
diff changeset
267 final Map<Path, Nodeid[]> file2rev2tag = new HashMap<Path, Nodeid[]>();
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 268
diff changeset
268 repository.getManifest().walk(new HgManifest.Inspector2() {
256
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
269 private int[] tagIndexAtRev = new int[4]; // it's unlikely there would be a lot of tags associated with a given cset
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
270
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
271 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
326
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
272 // may do better here using tagLocalRev2TagInfo, but need to change a lot, too lazy now
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
273 Nodeid cset = clogrmap.revision(changelogRevision);
256
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
274 Arrays.fill(tagIndexAtRev, -1);
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
275 for (int i = 0, x = 0; i < allTags.length; i++) {
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
276 if (cset.equals(allTags[i].revision())) {
256
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
277 tagIndexAtRev[x++] = i;
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
278 if (x == tagIndexAtRev.length) {
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
279 // expand twice as much
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
280 int[] expanded = new int[x << 1];
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
281 System.arraycopy(tagIndexAtRev, 0, expanded, 0, x);
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
282 expanded[x] = -1; // just in case there'd be no more tags associated with this cset
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
283 tagIndexAtRev = expanded;
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
284 }
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
285 }
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
286 }
256
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
287 if (tagIndexAtRev[0] == -1) {
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
288 System.out.println("Can't happen, provided we iterate over revisions with tags only");
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
289 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
290 return true;
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
291 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
292
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
293 public boolean next(Nodeid nid, String fname, String flags) {
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 268
diff changeset
294 throw new HgBadStateException(HgManifest.Inspector2.class.getName());
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 268
diff changeset
295 }
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 268
diff changeset
296
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 268
diff changeset
297 public boolean next(Nodeid nid, Path fname, HgManifest.Flags flags) {
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
298 Nodeid[] m = file2rev2tag.get(fname);
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
299 if (m == null) {
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
300 file2rev2tag.put(fname, m = new Nodeid[allTags.length]);
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
301 }
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
302 for (int tagIndex : tagIndexAtRev) {
256
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
303 if (tagIndex == -1) {
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
304 break;
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
305 }
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
306 if (m[tagIndex] != null) {
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
307 System.out.printf("There's another revision (%s) associated with tag %s already while we try to associate %s\n", m[tagIndex].shortNotation(), allTags[tagIndex].name(), nid.shortNotation());
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
308 }
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
309 m[tagIndex] = nid;
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
310 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
311 return true;
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
312 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
313
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
314 public boolean end(int manifestRevision) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
315 return true;
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
316 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
317
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
318 }, tagLocalRevs);
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
319 System.out.printf("Cache built: %d ms\n", System.currentTimeMillis() - start);
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
320 //
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
321 // look up specific file. This part is fast.
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
322 HgDataFile fileNode = repository.getFileNode(targetPath);
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 268
diff changeset
323 final Nodeid[] allTagsOfTheFile = file2rev2tag.get(targetPath);
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
324 // TODO if fileNode.isCopy, repeat for each getCopySourceName()
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
325 for (int localFileRev = 0; localFileRev < fileNode.getRevisionCount(); localFileRev++) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
326 Nodeid fileRev = fileNode.getRevision(localFileRev);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
327 int changesetLocalRev = fileNode.getChangesetLocalRevision(localFileRev);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
328 List<String> associatedTags = new LinkedList<String>();
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
329 for (int i = 0; i < allTagsOfTheFile.length; i++) {
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
330 if (fileRev.equals(allTagsOfTheFile[i])) {
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
331 associatedTags.add(allTags[i].name());
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
332 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
333 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
334 System.out.printf("%3d%7d%s\n", localFileRev, changesetLocalRev, associatedTags);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
335 }
326
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
336 }
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
337
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
338 private void collectTagsPerFile_Approach_2(HgRepository repository, final int[] tagLocalRevs, final IntMap<List<TagInfo>> tagLocalRev2TagInfo, TagInfo[] allTags, Path targetPath) {
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
339 //
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
340 // Approach 2. No all-file map. Collect file revisions recorded at the time of tagging,
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
341 // then for each file revision check if it is among those above, and if yes, take corresponding tags
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
342 HgDataFile fileNode = repository.getFileNode(targetPath);
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
343 final long start2 = System.nanoTime();
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
344 final int lastRev = fileNode.getLastRevision();
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
345 final Map<Integer, Nodeid> fileRevisionAtTagRevision = repository.getManifest().getFileRevisions(targetPath, tagLocalRevs);
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
346 final long start2a = System.nanoTime();
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
347 fileNode.walk(0, lastRev, new HgDataFile.RevisionInspector() {
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
348
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
349 public void next(int localFileRev, Nodeid fileRevision, int linkedRevision) {
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
350 int changesetLocalRev = linkedRevision;
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
351 List<String> associatedTags = new LinkedList<String>();
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
352 for (int taggetRevision : tagLocalRevs) {
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
353 // current file revision can't appear in tags that point to earlier changelog revisions (they got own file revision)
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
354 if (taggetRevision >= changesetLocalRev) {
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
355 // z points to some changeset with tag
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
356 Nodeid wasKnownAs = fileRevisionAtTagRevision.get(taggetRevision);
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
357 if (wasKnownAs.equals(fileRevision)) {
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
358 // has tag associated with changeset at index z
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
359 List<TagInfo> tagsAtRev = tagLocalRev2TagInfo.get(taggetRevision);
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
360 assert tagsAtRev != null;
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
361 for (TagInfo ti : tagsAtRev) {
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
362 associatedTags.add(ti.name());
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
363 }
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
364 }
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
365 }
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
366 }
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
367 System.out.printf("%3d%7d%s\n", localFileRev, changesetLocalRev, associatedTags);
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
368 }
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
369 });
d42a45a2c9d6 Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 324
diff changeset
370 System.out.printf("Alternative total time: %d ms, of that init: %d ms\n", (System.nanoTime() - start2)/1000000, (start2a-start2)/1000000);
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
371 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
372 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
373
329
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
374 static class DoNothingManifestInspector implements HgManifest.Inspector2 {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
375 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
376 return true;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
377 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
378 public boolean next(Nodeid nid, String fname, String flags) {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
379 throw new HgBadStateException(HgManifest.Inspector2.class.getName());
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
380 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
381 public boolean next(Nodeid nid, Path fname, Flags flags) {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
382 return true;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
383 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
384 public boolean end(int manifestRevision) {
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
385 return true;
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
386 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
387 }
694ebabb5cb3 Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 326
diff changeset
388
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
389 public static void main2(String[] args) throws HgException, CancelledException {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
390 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
391 final Path targetPath = Path.create("README");
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
392 final HgTags tags = repository.getTags();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
393 final Map<String, HgTags.TagInfo> tagToInfo = tags.getTags();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
394 final HgManifest manifest = repository.getManifest();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
395 final Map<Nodeid, List<String>> changeSetRevisionToTags = new HashMap<Nodeid, List<String>>();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
396 final HgDataFile fileNode = repository.getFileNode(targetPath);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
397 for (String tagName : tagToInfo.keySet()) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
398 final HgTags.TagInfo info = tagToInfo.get(tagName);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
399 final Nodeid nodeId = info.revision();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
400 // TODO: This is not correct as we can't be sure that file at the corresponding revision is actually our target file (which may have been renamed, etc.)
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
401 final Nodeid fileRevision = manifest.getFileRevision(repository.getChangelog().getLocalRevision(nodeId), targetPath);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
402 if (fileRevision == null) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
403 continue;
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
404 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
405
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
406 final Nodeid changeSetRevision = fileNode.getChangesetRevision(fileRevision);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
407 List<String> revisionTags = changeSetRevisionToTags.get(changeSetRevision);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
408 if (revisionTags == null) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
409 revisionTags = new ArrayList<String>();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
410 changeSetRevisionToTags.put(changeSetRevision, revisionTags);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
411 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
412 revisionTags.add(tagName);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
413 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
414
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
415 final HgLogCommand logCommand = new HgLogCommand(repository);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
416 logCommand.file(targetPath, true);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
417 logCommand.execute(new HgChangesetHandler() {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
418 public void next(HgChangeset changeset) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
419 if (changeset.getAffectedFiles().contains(targetPath)) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
420 System.out.println(changeset.getRevision() + " " + changeSetRevisionToTags.get(changeset.getNodeid()));
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
421 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
422 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
423 });
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
424 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
425 }