annotate test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java @ 256:b61ed0f2c4da

Yet another slight perf/mem improvement for the tags per file sample
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 16 Aug 2011 15:45:47 +0200
parents 5a6ab50b4cbf
children ea0c0de86d0e
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;
256
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
5 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
6 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
7 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
8 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
9 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
10
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
11 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
12 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
13 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
14 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
15 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
16 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
17 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
18 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
19 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
20 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
21 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
22 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
23 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
24 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
25 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
26
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 /**
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 * @author Marc Strapetz
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 */
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 public class MapTagsToFileRevisions {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 // Static =================================================================
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33
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
34 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
35 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
36 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
37 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
38 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
39 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
40 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
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
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
43 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
44 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
45 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
46 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
47 //
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 // 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
49 //
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 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
51 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
52 // 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
53 // 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
54 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
55 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
56 // 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
57 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
58 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
59 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
60 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
61 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
62 }
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
63 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
64 //
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 repository.getManifest().walk(new HgManifest.Inspector() {
256
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
66 private int[] tagIndexAtRev = new int[4]; // it's unlikely there would be a lot of tags associated with a given cset
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
67 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
68 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
69
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 // 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
78 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
79 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
80 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
81 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
82 }
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
83 }
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
84 }
256
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
85 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
86 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
87 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 return true;
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 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
92 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
93 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
94 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
95 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
96 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
97 }
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
98 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
99 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
100 break;
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
101 }
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
102 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
103 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
104 }
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
105 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
106 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 return true;
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 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
111 return true;
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 }, 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
115 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
116 //
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 // 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
118 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
119 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
120 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
121 // 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
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 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
132 }
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
133 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
134 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
135 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146 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
147 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
148 // 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
149 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
150 if (fileRevision == null) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 continue;
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 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
155 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
156 if (revisionTags == null) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157 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
158 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
159 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
160 revisionTags.add(tagName);
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
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163 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
164 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
165 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
166 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
167 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
168 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
169 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 });
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 }