Mercurial > hg4j
annotate test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java @ 255:5a6ab50b4cbf
Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 16 Aug 2011 14:33:11 +0200 |
parents | a620f0663a37 |
children | b61ed0f2c4da |
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 |
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
|
3 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
|
4 import java.util.ArrayList; |
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.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
|
6 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
|
7 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
|
8 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
|
9 |
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
|
10 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
|
11 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
|
12 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
|
13 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
|
14 import org.tmatesoft.hg.core.Nodeid; |
254
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 import org.tmatesoft.hg.internal.Pool; |
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
|
16 import org.tmatesoft.hg.repo.HgChangelog; |
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.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
|
18 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
|
19 import org.tmatesoft.hg.repo.HgManifest; |
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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 /** |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 * @author Marc Strapetz |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 */ |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 public class MapTagsToFileRevisions { |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 // Static ================================================================= |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 |
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
|
33 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
|
34 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
|
35 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
|
36 m.main(); |
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
|
37 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
|
38 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
|
39 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
|
40 } |
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 |
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 private void main() 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
|
43 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
|
44 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
|
45 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
|
46 // |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 // 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
|
48 // |
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 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
|
50 tags.getTags().values().toArray(allTags); |
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 // 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
|
52 // is index of corresponding TagInfo in allTags; |
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
|
53 final Map<String, Nodeid[]> file2rev2tag = new HashMap<String, Nodeid[]>(); |
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
|
54 System.out.printf("Collecting manifests for %d tags\n", allTags.length); |
254
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 // effective translation of changeset revisions to their local indexes |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 final HgChangelog.RevisionMap clogrmap = repository.getChangelog().new RevisionMap().init(); |
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
|
57 int[] tagLocalRevs = new int[allTags.length]; |
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
|
58 for (int i = 0; i < allTags.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
|
59 final Nodeid tagRevision = allTags[i].revision(); |
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
|
60 tagLocalRevs[i] = clogrmap.localRevision(tagRevision); |
254
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 } |
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
|
62 System.out.printf("Prepared tag revisions to analyze: %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
|
63 // |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 repository.getManifest().walk(new HgManifest.Inspector() { |
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
|
65 private final ArrayList<Integer> tagIndexAtRev = new ArrayList<Integer>(); |
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
|
66 private final Pool<String> filenamePool = new Pool<String>(); |
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
|
67 private final Pool<Nodeid> nodeidPool = new Pool<Nodeid>(); |
254
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) { |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 Nodeid cset = clogrmap.revision(changelogRevision); |
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
|
71 tagIndexAtRev.clear(); |
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
|
72 for (int i = 0; i < allTags.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
|
73 if (cset.equals(allTags[i].revision())) { |
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
|
74 tagIndexAtRev.add(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
|
75 } |
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
|
76 } |
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
|
77 if (tagIndexAtRev.isEmpty()) { |
254
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 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
|
79 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 return true; |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 public boolean next(Nodeid nid, String fname, String flags) { |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 fname = filenamePool.unify(fname); |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 nid = nodeidPool.unify(nid); |
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
|
86 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
|
87 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
|
88 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
|
89 } |
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
|
90 for (int tagIndex : tagIndexAtRev) { |
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
|
91 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
|
92 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
|
93 } |
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
|
94 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
|
95 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 return true; |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 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
|
100 return true; |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 }, 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
|
104 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
|
105 // |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 // 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
|
107 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
|
108 HgDataFile fileNode = repository.getFileNode(targetPath); |
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
|
109 final Nodeid[] allTagsOfTheFile = file2rev2tag.get(targetPath.toString()); |
254
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 // 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 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
|
121 } |
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
|
122 System.out.printf("Total time: %d ms\n", System.currentTimeMillis() - start); |
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
|
123 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
|
124 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 // 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
|
138 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
|
139 if (fileRevision == null) { |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 continue; |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 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
|
144 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
|
145 if (revisionTags == null) { |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 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
|
147 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
|
148 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 revisionTags.add(tagName); |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
159 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
160 }); |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
161 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
162 } |