Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/HgManifest.java @ 264:6bb5e7ed051a
Optimize memory usage (reduce number of objects instantiated) when pooling file names and nodeids during manifest parsing
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 19 Aug 2011 03:36:25 +0200 |
parents | 3dcd3dd90c77 |
children | 0a2f445de774 |
comparison
equal
deleted
inserted
replaced
263:31f67be94e71 | 264:6bb5e7ed051a |
---|---|
27 import org.tmatesoft.hg.core.Nodeid; | 27 import org.tmatesoft.hg.core.Nodeid; |
28 import org.tmatesoft.hg.internal.DataAccess; | 28 import org.tmatesoft.hg.internal.DataAccess; |
29 import org.tmatesoft.hg.internal.Experimental; | 29 import org.tmatesoft.hg.internal.Experimental; |
30 import org.tmatesoft.hg.internal.Lifecycle; | 30 import org.tmatesoft.hg.internal.Lifecycle; |
31 import org.tmatesoft.hg.internal.Pool; | 31 import org.tmatesoft.hg.internal.Pool; |
32 import org.tmatesoft.hg.internal.Pool2; | |
32 import org.tmatesoft.hg.internal.RevlogStream; | 33 import org.tmatesoft.hg.internal.RevlogStream; |
33 import org.tmatesoft.hg.util.Path; | 34 import org.tmatesoft.hg.util.Path; |
34 | 35 |
35 | 36 |
36 /** | 37 /** |
147 boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision); | 148 boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision); |
148 boolean next(Nodeid nid, String fname, String flags); | 149 boolean next(Nodeid nid, String fname, String flags); |
149 boolean end(int manifestRevision); | 150 boolean end(int manifestRevision); |
150 } | 151 } |
151 | 152 |
152 private static class ManifestParser implements RevlogStream.Inspector { | 153 private static class ManifestParser implements RevlogStream.Inspector/*, Lifecycle*/ { |
153 private boolean gtg = true; // good to go | 154 private boolean gtg = true; // good to go |
154 private final Inspector inspector; | 155 private final Inspector inspector; |
155 private Pool<Nodeid> nodeidPool; | 156 private Pool2<Nodeid> nodeidPool, thisRevPool; |
156 private final Pool<String> fnamePool; | 157 private final Pool2<String> fnamePool; |
157 private final Pool<String> flagsPool; | 158 private final Pool<String> flagsPool; |
158 | 159 |
159 public ManifestParser(Inspector delegate) { | 160 public ManifestParser(Inspector delegate) { |
160 assert delegate != null; | 161 assert delegate != null; |
161 inspector = delegate; | 162 inspector = delegate; |
162 nodeidPool = new Pool<Nodeid>(); | 163 nodeidPool = new Pool2<Nodeid>(); |
163 fnamePool = new Pool<String>(); | 164 fnamePool = new Pool2<String>(); |
164 flagsPool = new Pool<String>(); | 165 flagsPool = new Pool<String>(); |
166 thisRevPool = new Pool2<Nodeid>(); | |
165 } | 167 } |
166 | 168 |
167 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) { | 169 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) { |
168 if (!gtg) { | 170 if (!gtg) { |
169 return; | 171 return; |
170 } | 172 } |
171 try { | 173 try { |
172 gtg = gtg && inspector.begin(revisionNumber, new Nodeid(nodeid, true), linkRevision); | 174 gtg = gtg && inspector.begin(revisionNumber, new Nodeid(nodeid, true), linkRevision); |
173 Pool<Nodeid> thisRevPool = new Pool<Nodeid>(nodeidPool.size()); // supply hint to minimize map resize/rehash | |
174 String fname = null; | 175 String fname = null; |
175 String flags = null; | 176 String flags = null; |
176 Nodeid nid = null; | 177 Nodeid nid = null; |
177 final char[] nodeidConvertCache = new char[40]; | 178 final char[] nodeidConvertCache = new char[40]; |
178 String data = new String(da.byteArray()); | 179 String data = new String(da.byteArray()); |
214 // | 215 // |
215 // keep only actual file revisions, found at this version | 216 // keep only actual file revisions, found at this version |
216 // (next manifest is likely to refer to most of them, although in specific cases | 217 // (next manifest is likely to refer to most of them, although in specific cases |
217 // like commit in another branch a lot may be useless) | 218 // like commit in another branch a lot may be useless) |
218 nodeidPool.clear(); | 219 nodeidPool.clear(); |
220 Pool2<Nodeid> t = nodeidPool; | |
219 nodeidPool = thisRevPool; | 221 nodeidPool = thisRevPool; |
222 thisRevPool = t; | |
220 } catch (IOException ex) { | 223 } catch (IOException ex) { |
221 throw new HgBadStateException(ex); | 224 throw new HgBadStateException(ex); |
222 } | 225 } |
223 } | 226 } |
227 // | |
228 // public void start(int count, Callback callback, Object token) { | |
229 // } | |
230 // | |
231 // public void finish(Object token) { | |
232 // System.out.println(fnamePool); | |
233 // System.out.println(nodeidPool); | |
234 // System.out.printf("Free mem once parse done: %,d\n", Runtime.getRuntime().freeMemory()); | |
235 // } | |
224 } | 236 } |
225 | 237 |
226 private static class RevisionMapper implements RevlogStream.Inspector, Lifecycle { | 238 private static class RevisionMapper implements RevlogStream.Inspector, Lifecycle { |
227 | 239 |
228 private final int changelogRevisions; | 240 private final int changelogRevisions; |