Mercurial > jhg
comparison cmdline/org/tmatesoft/hg/console/Main.java @ 574:88afffd39899
Improve memory consumption of HgManifest#getFileRevision(): avoid extra byte[] instances
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 16 Apr 2013 14:44:57 +0200 |
parents | 2f9ed6bcefa2 |
children | 3c4db86e8c1f |
comparison
equal
deleted
inserted
replaced
573:e49f9d9513fa | 574:88afffd39899 |
---|---|
26 import java.util.HashSet; | 26 import java.util.HashSet; |
27 import java.util.List; | 27 import java.util.List; |
28 import java.util.Map; | 28 import java.util.Map; |
29 | 29 |
30 import org.tmatesoft.hg.core.HgChangeset; | 30 import org.tmatesoft.hg.core.HgChangeset; |
31 import org.tmatesoft.hg.core.HgChangesetFileSneaker; | |
31 import org.tmatesoft.hg.core.HgChangesetTreeHandler; | 32 import org.tmatesoft.hg.core.HgChangesetTreeHandler; |
32 import org.tmatesoft.hg.core.HgCheckoutCommand; | 33 import org.tmatesoft.hg.core.HgCheckoutCommand; |
33 import org.tmatesoft.hg.core.HgException; | 34 import org.tmatesoft.hg.core.HgException; |
34 import org.tmatesoft.hg.core.HgFileRenameHandlerMixin; | 35 import org.tmatesoft.hg.core.HgFileRenameHandlerMixin; |
35 import org.tmatesoft.hg.core.HgFileRevision; | 36 import org.tmatesoft.hg.core.HgFileRevision; |
40 import org.tmatesoft.hg.core.Nodeid; | 41 import org.tmatesoft.hg.core.Nodeid; |
41 import org.tmatesoft.hg.internal.BasicSessionContext; | 42 import org.tmatesoft.hg.internal.BasicSessionContext; |
42 import org.tmatesoft.hg.internal.ByteArrayChannel; | 43 import org.tmatesoft.hg.internal.ByteArrayChannel; |
43 import org.tmatesoft.hg.internal.ConfigFile; | 44 import org.tmatesoft.hg.internal.ConfigFile; |
44 import org.tmatesoft.hg.internal.DigestHelper; | 45 import org.tmatesoft.hg.internal.DigestHelper; |
46 import org.tmatesoft.hg.internal.ManifestRevision; | |
45 import org.tmatesoft.hg.internal.PathGlobMatcher; | 47 import org.tmatesoft.hg.internal.PathGlobMatcher; |
46 import org.tmatesoft.hg.internal.RelativePathRewrite; | 48 import org.tmatesoft.hg.internal.RelativePathRewrite; |
47 import org.tmatesoft.hg.internal.StreamLogFacility; | 49 import org.tmatesoft.hg.internal.StreamLogFacility; |
48 import org.tmatesoft.hg.repo.HgBookmarks; | 50 import org.tmatesoft.hg.repo.HgBookmarks; |
49 import org.tmatesoft.hg.repo.HgBranches; | 51 import org.tmatesoft.hg.repo.HgBranches; |
98 System.out.println("REPO:" + hgRepo.getLocation()); | 100 System.out.println("REPO:" + hgRepo.getLocation()); |
99 } | 101 } |
100 | 102 |
101 public static void main(String[] args) throws Exception { | 103 public static void main(String[] args) throws Exception { |
102 Main m = new Main(args); | 104 Main m = new Main(args); |
103 m.testRevert(); | 105 m.checkFileSneakerPerformance2(); |
106 // m.testRevert(); | |
104 // m.testCheckout(); | 107 // m.testCheckout(); |
105 // m.tryExtensions(); | 108 // m.tryExtensions(); |
106 // m.dumpBookmarks(); | 109 // m.dumpBookmarks(); |
107 // m.readConfigFile(); | 110 // m.readConfigFile(); |
108 // m.dumpCommitLastMessage(); | 111 // m.dumpCommitLastMessage(); |
124 // m.catCompleteHistory(); | 127 // m.catCompleteHistory(); |
125 // m.dumpCompleteManifestLow(); | 128 // m.dumpCompleteManifestLow(); |
126 // m.dumpCompleteManifestHigh(); | 129 // m.dumpCompleteManifestHigh(); |
127 // m.bunchOfTests(); | 130 // m.bunchOfTests(); |
128 } | 131 } |
132 | |
133 private void checkFileSneakerPerformance() throws Exception { | |
134 HgChangesetFileSneaker fs1 = new HgChangesetFileSneaker(hgRepo); | |
135 HgChangesetFileSneaker fs2 = new HgChangesetFileSneaker(hgRepo); | |
136 fs1.followRenames(true); | |
137 fs2.followRenames(true); | |
138 Nodeid cset = hgRepo.getChangelog().getRevision(TIP); | |
139 Path fname = Path.create("dir3/file8"); | |
140 fs1.changeset(cset); | |
141 fs2.changeset(cset); | |
142 // hgRepo.getManifest().getFileRevision(TIP, fname); | |
143 final long start1 = System.nanoTime(); | |
144 boolean e1 = fs1.checkExists(fname); | |
145 final long end1 = System.nanoTime(); | |
146 boolean e2 = fs2.checkExists(fname); | |
147 final long end2 = System.nanoTime(); | |
148 Nodeid fr = hgRepo.getManifest().getFileRevision(TIP, fname); | |
149 final long end3 = System.nanoTime(); | |
150 System.out.printf("\t1st run: %d ms, %b\n\t2nd run: %d ms, %b\n\tfile only: %d ms", (end1 - start1) / 1000000, e1, (end2 - end1) / 1000000, e2, (end3-end2)/1000000); | |
151 if (!fr.equals(fs1.revision()) || !fr.equals(fs2.revision())) { | |
152 throw new AssertionError(); | |
153 } | |
154 ManifestRevision mr = new ManifestRevision(null, null); | |
155 final long _s1 = System.nanoTime(); | |
156 hgRepo.getManifest().walk(2, 2, mr); | |
157 final long _e1 = System.nanoTime(); | |
158 hgRepo.getManifest().getFileRevision(2, fname); | |
159 final long _e2 = System.nanoTime(); | |
160 System.out.printf("\n\tManifestRevision:%d ms, getFileRevision:%d ms\n", (_e1-_s1)/1000000, (_e2-_e1)/1000000); | |
161 } | |
162 | |
163 // -agentlib:hprof=cpu=times,heap=sites,depth=10 | |
164 private void checkFileSneakerPerformance2() throws Exception { | |
165 Path fname = Path.create("dir3/file8"); | |
166 hgRepo.getManifest().getFileRevision(2, fname); | |
167 // ManifestRevision mr = new ManifestRevision(null, null); | |
168 // hgRepo.getManifest().walk(2, 2, mr); | |
169 } | |
170 | |
129 | 171 |
130 private void testRevert() throws Exception { | 172 private void testRevert() throws Exception { |
131 HgRevertCommand cmd = new HgRevertCommand(hgRepo); | 173 HgRevertCommand cmd = new HgRevertCommand(hgRepo); |
132 cmd.file(Path.create("a.txt")).execute(); | 174 cmd.file(Path.create("a.txt")).execute(); |
133 } | 175 } |