Mercurial > hg4j
annotate test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java @ 326:d42a45a2c9d6
Alternative tag collection approach for a file history
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 04 Oct 2011 06:28:01 +0200 |
parents | 283b294d1079 |
children | 694ebabb5cb3 |
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()); |
326
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
43 m.collectTagsPerFile(); |
307
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
44 // m.manifestWalk(); |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
45 // m.changelogWalk(); |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
46 // m.revisionMap(); |
326
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
47 // 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
|
48 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
|
49 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
|
50 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
|
51 } |
324
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
52 |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
53 /* |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
54 * .hgtags, 261 revisions |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
55 * 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
|
56 * 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
|
57 * README, 465 revisions |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
58 * 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
|
59 * 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
|
60 * configure.in, 1109 revisions |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
61 * 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
|
62 * 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
|
63 */ |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
64 private void buildFile2ChangelogRevisionMap() throws Exception { |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
65 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
|
66 final HgChangelog clog = repository.getChangelog(); |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
67 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
|
68 // warm-up |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
69 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
|
70 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
|
71 // |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
72 final int latestRevision = fileNode.getLastRevision(); |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
73 // |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
74 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
|
75 fileMap = fileNode.new RevisionMap().init(); |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 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
|
80 // 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
|
81 int localCset = fileNode.getChangesetLocalRevision(revision); |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
82 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
|
83 changesetToNodeid_1.put(changesetId, nodeId); |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
84 } |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
85 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
|
86 // |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
87 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
|
88 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 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 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
|
91 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
|
92 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
|
93 Nodeid nidFile = fileMap.revision(revision); |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
94 int localCset = fileNode.getChangesetLocalRevision(revision); |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
95 Nodeid nidCset = clogMap.revision(localCset); |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
96 changesetToNodeid_2.put(nidCset, nidFile); |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
97 } |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
98 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
|
99 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
|
100 // |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
105 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
|
106 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
|
107 } |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
108 }); |
283b294d1079
Explore alternatives to access file-changelog combined history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 } |
263
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
115 |
307
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
116 /* |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
117 * 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
|
118 * Direct clog.getLocalRevision: ~260 ms |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
119 * 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
|
120 * 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
|
121 * 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
|
122 * 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
|
123 */ |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
124 private void revisionMap() throws Exception { |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
125 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
|
126 final HgChangelog clog = repository.getChangelog(); |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
127 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
|
128 final int step = 5000; |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
129 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
|
130 revisions.add(clog.getRevision(i)); |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
131 } |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
132 final long s1 = System.nanoTime(); |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
133 for (Nodeid n : revisions) { |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
134 int r = clog.getLocalRevision(n); |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
135 if (r % step != 0) { |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
136 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
|
137 } |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
138 } |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
139 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
|
140 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
|
141 final long s2 = System.nanoTime(); |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
142 rmap.init(); |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
143 final long s3 = System.nanoTime(); |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
144 for (Nodeid n : revisions) { |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
145 int r = rmap.localRevision(n); |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
146 if (r % step != 0) { |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
147 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
|
148 } |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
149 } |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
150 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
|
151 } |
2f2ab5c27f41
Collect sort reverse indexes along with array sorting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
304
diff
changeset
|
152 |
263
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
153 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
|
154 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
|
155 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
|
156 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
|
157 public int xx = 0; |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
158 |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
159 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
|
160 if (xx+revisionNumber < 0) { |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
161 System.out.println(xx); |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
162 System.out.println(revisionNumber); |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
163 } |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
164 xx += revisionNumber; |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
165 } |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
166 }); |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
167 // 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
|
168 // 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
|
169 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
|
170 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
|
171 } |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
172 |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
173 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
|
174 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
|
175 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
|
176 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython")); |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
177 repository.getManifest().walk(0, 10000, new HgManifest.Inspector2() { |
263
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
178 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) { |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
179 return true; |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
180 } |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
181 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
|
182 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
|
183 } |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
184 public boolean next(Nodeid nid, Path fname, Flags flags) { |
263
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
185 return true; |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
186 } |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
187 public boolean end(int manifestRevision) { |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
188 return true; |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
189 } |
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 // 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
|
192 // 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
|
193 // 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
|
194 // 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
|
195 // 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
|
196 // |
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
|
197 // 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
|
198 // 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
|
199 // 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
|
200 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
|
201 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
|
202 } |
326
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
203 |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
204 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
|
205 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
|
206 int x = 0; |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 if (tagLocalRev != HgRepository.BAD_REVISION) { |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
211 tagLocalRevs[x++] = tagLocalRev; |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
212 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
|
213 if (tagsAssociatedWithRevision == null) { |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
214 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
|
215 } |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
216 tagsAssociatedWithRevision.add(allTags[i]); |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
217 } |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
218 } |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
219 if (x != allTags.length) { |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
220 // 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
|
221 int[] copy = new int[x]; |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
222 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
|
223 tagLocalRevs = copy; |
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 return tagLocalRevs; |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
226 } |
263
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
227 |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
259
diff
changeset
|
228 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
|
229 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
|
230 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
|
231 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
|
232 // |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
233 // 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
|
234 // |
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
|
235 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
|
236 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
|
237 // 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
|
238 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
|
239 // 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
|
240 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
|
241 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
|
242 final int[] tagLocalRevs = collectLocalTagRevisions(clogrmap, allTags, tagLocalRev2TagInfo); |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
243 System.out.printf("Prepared tag revisions to analyze: %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
|
244 |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
245 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
|
246 // |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
247 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
|
248 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
|
249 |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
250 System.out.println("\nApproach 2"); |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
251 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
|
252 } |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
253 |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
254 // 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
|
255 // |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
256 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
|
257 HgRepository repository = clogrmap.getRepo(); |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
258 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
|
259 // 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
|
260 // 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
|
261 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
|
262 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
|
263 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
|
264 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
265 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
|
266 // 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 // 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 } |
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
|
279 } |
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
|
280 } |
256
b61ed0f2c4da
Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
255
diff
changeset
|
281 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
|
282 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
|
283 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
284 return true; |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
285 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
286 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
287 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
|
288 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
|
289 } |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
290 |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
291 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
|
292 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
|
293 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
|
294 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
|
295 } |
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
|
296 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
|
297 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
|
298 break; |
b61ed0f2c4da
Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
255
diff
changeset
|
299 } |
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 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
|
301 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
|
302 } |
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
|
303 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
|
304 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
305 return true; |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
306 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
307 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
308 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
|
309 return true; |
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 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
312 }, 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
|
313 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
|
314 // |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
315 // 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
|
316 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
|
317 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
|
318 // 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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 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
|
326 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
327 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
328 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
|
329 } |
326
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
330 } |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
331 |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
332 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
|
333 // |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
334 // 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
|
335 // 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
|
336 HgDataFile fileNode = repository.getFileNode(targetPath); |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
337 final long start2 = System.nanoTime(); |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
338 final int lastRev = fileNode.getLastRevision(); |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
339 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
|
340 final long start2a = System.nanoTime(); |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
341 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
|
342 |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
343 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
|
344 int changesetLocalRev = linkedRevision; |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
345 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
|
346 for (int taggetRevision : tagLocalRevs) { |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
347 // 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
|
348 if (taggetRevision >= changesetLocalRev) { |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
349 // 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
|
350 Nodeid wasKnownAs = fileRevisionAtTagRevision.get(taggetRevision); |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
351 if (wasKnownAs.equals(fileRevision)) { |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
352 // 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
|
353 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
|
354 assert tagsAtRev != null; |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
355 for (TagInfo ti : tagsAtRev) { |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
356 associatedTags.add(ti.name()); |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
357 } |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
358 } |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
359 } |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
360 } |
d42a45a2c9d6
Alternative tag collection approach for a file history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
324
diff
changeset
|
361 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
|
362 } |
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 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
|
365 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
|
366 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
367 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
368 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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 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
|
374 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
|
375 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
|
376 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
|
377 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
|
378 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
|
379 // 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
|
380 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
|
381 if (fileRevision == null) { |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
382 continue; |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
383 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
384 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
385 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
|
386 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
|
387 if (revisionTags == null) { |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
388 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
|
389 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
|
390 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
391 revisionTags.add(tagName); |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
392 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
393 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
394 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
|
395 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
|
396 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
|
397 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
|
398 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
|
399 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
|
400 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
401 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
402 }); |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
403 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
404 } |