diff test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java @ 263:31f67be94e71

RevlogStream - reduce number of object instances, reuse when possible
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 18 Aug 2011 18:06:44 +0200
parents ea0c0de86d0e
children c5980f287cc4
line wrap: on
line diff
--- a/test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java	Thu Aug 18 03:46:36 2011 +0200
+++ b/test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java	Thu Aug 18 18:06:44 2011 +0200
@@ -7,6 +7,7 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
 
 import org.tmatesoft.hg.core.HgChangeset;
 import org.tmatesoft.hg.core.HgChangesetHandler;
@@ -19,6 +20,7 @@
 import org.tmatesoft.hg.repo.HgManifest;
 import org.tmatesoft.hg.repo.HgRepository;
 import org.tmatesoft.hg.repo.HgTags;
+import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
 import org.tmatesoft.hg.repo.HgTags.TagInfo;
 import org.tmatesoft.hg.util.CancelledException;
 import org.tmatesoft.hg.util.Path;
@@ -33,13 +35,63 @@
 	public static void main(String[] args) throws Exception {
 		MapTagsToFileRevisions m = new MapTagsToFileRevisions();
 		System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
-		m.main();
+//		Pattern p = Pattern.compile("^doc/[^/]*?\\.[0-9]\\.(x|ht)ml");
+//		System.out.println(p.matcher("doc/asd.2.xml").matches());
+//		System.out.println(p.matcher("doc/zxc.6.html").matches());
+		m.collectTagsPerFile();
+//		m.manifestWalk();
 		m = null;
 		System.gc();
 		System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
 	}
-	
-	private void main() throws HgException, CancelledException {
+
+	private void changelogWalk() throws Exception {
+		final long start = System.currentTimeMillis();
+		final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
+		repository.getChangelog().all(new HgChangelog.Inspector() {
+			public int xx = 0;
+			
+			public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
+				if (xx+revisionNumber < 0) {
+					System.out.println(xx);
+					System.out.println(revisionNumber);
+				}
+				xx += revisionNumber;
+			}
+		});
+		// cpython: 17 seconds, mem  132,9 -> 129,0 -> 131,7
+		// cpyhton: 13 seconds. Of that, cumulative Patch.apply takes 8.8 seconds, RevlogStream.Inspector.next - 1.8
+		System.out.printf("Total time: %d ms\n", System.currentTimeMillis() - start);
+		System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
+	}
+
+	private void manifestWalk() throws Exception {
+		final long start = System.currentTimeMillis();
+		final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
+		repository.getManifest().walk(0, 10000, new HgManifest.Inspector() {
+
+			public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
+				return true;
+			}
+
+			public boolean next(Nodeid nid, String fname, String flags) {
+				return true;
+			}
+
+			public boolean end(int manifestRevision) {
+				return true;
+			}
+		});
+		// cpython: 1,1 sec for 0..1000, 43 sec for 0..10000, 115 sec for 0..20000 (Pool with HashMap)
+		// 2,4 sec for 1000..2000
+		// cpython -r 1000: 484 files, -r 2000: 1015 files. Iteration 1000..2000; fnamePool.size:1019 nodeidPool.size:2989
+		// nodeidPool for two subsequent revisions only: 840. 37 sec for 0..10000. 99 sec for 0..20k
+		// 0..10000 fnamePool: hits:15989152, misses:3020
+		System.out.printf("Total time: %d ms\n", System.currentTimeMillis() - start);
+		System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
+	}
+
+	private void collectTagsPerFile() throws HgException, CancelledException {
 		final long start = System.currentTimeMillis();
 		final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
 		final HgTags tags = repository.getTags();
@@ -71,6 +123,31 @@
 		}
 		System.out.printf("Prepared tag revisions to analyze: %d ms\n", System.currentTimeMillis() - start);
 		//
+		final int[] counts = new int[2];
+		HgManifest.Inspector emptyInsp = new HgManifest.Inspector() {
+			public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
+				counts[0]++;
+				return true;
+			}
+			public boolean next(Nodeid nid, String fname, String flags) {
+				counts[1]++;
+				return true;
+			}
+			public boolean end(int manifestRevision) {
+				return true;
+			}
+		};
+//		final long start0 = System.currentTimeMillis();
+//		repository.getManifest().walk(emptyInsp, tagLocalRevs[0]); // warm-up
+//		final long start1 = System.currentTimeMillis();
+//		repository.getManifest().walk(emptyInsp, tagLocalRevs[0]); // warm-up
+//		counts[0] = counts[1] = 0;
+//		final long start2 = System.currentTimeMillis();
+//		repository.getManifest().walk(emptyInsp, tagLocalRevs);
+//		// No-op iterate over selected revisions: 11719 ms (revs:189, files: 579652), warm-up: 218 ms.  Cache built: 25281 ms
+//		// No-op iterate over selected revisions: 11719 ms (revs:189, files: 579652), warm-up1: 234 ms, warm-up2: 16 ms.  Cache built: 25375 ms
+//		System.out.printf("No-op iterate over selected revisions: %d ms (revs:%d, files: %d), warm-up1: %d ms, warm-up2: %d ms \n", System.currentTimeMillis() - start2, counts[0], counts[1], start1-start0, start2-start1);
+		//
 		repository.getManifest().walk(new HgManifest.Inspector() {
 			private int[] tagIndexAtRev = new int[4]; // it's unlikely there would be a lot of tags associated with a given cset