Mercurial > public > mercurial-scm > hg
comparison mercurial/branchmap.py @ 40425:5e5c8f2a1eb5
branchmap: do not specify changelog as an argument
Since (unfiltered)repo.changelog lookup gets as fast as __dict__ lookup,
there's no point to pass in changelog instance.
$ hg perfbranchmap --clear-revbranch -R mozilla-central
! base
(orig) wall 20.593091 comb 20.600000 user 20.520000 sys 0.080000 (best of 3)
(this) wall 20.129126 comb 20.130000 user 20.020000 sys 0.110000 (best of 3)
This backs out most of the changes in 76d4272bd57b and 47c03042cd1d.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 23 Oct 2018 21:11:13 +0900 |
parents | 76d4272bd57b |
children | 50a64c321c1e |
comparison
equal
deleted
inserted
replaced
40424:7caf632e30c3 | 40425:5e5c8f2a1eb5 |
---|---|
279 cl = repo.changelog | 279 cl = repo.changelog |
280 # collect new branch entries | 280 # collect new branch entries |
281 newbranches = {} | 281 newbranches = {} |
282 getbranchinfo = repo.revbranchcache().branchinfo | 282 getbranchinfo = repo.revbranchcache().branchinfo |
283 for r in revgen: | 283 for r in revgen: |
284 branch, closesbranch = getbranchinfo(r, changelog=cl) | 284 branch, closesbranch = getbranchinfo(r) |
285 newbranches.setdefault(branch, []).append(r) | 285 newbranches.setdefault(branch, []).append(r) |
286 if closesbranch: | 286 if closesbranch: |
287 self._closednodes.add(cl.node(r)) | 287 self._closednodes.add(cl.node(r)) |
288 | 288 |
289 # fetch current topological heads to speed up filtering | 289 # fetch current topological heads to speed up filtering |
405 self._rbcnamescount = 0 | 405 self._rbcnamescount = 0 |
406 self._namesreverse.clear() | 406 self._namesreverse.clear() |
407 self._rbcrevslen = len(self._repo.changelog) | 407 self._rbcrevslen = len(self._repo.changelog) |
408 self._rbcrevs = bytearray(self._rbcrevslen * _rbcrecsize) | 408 self._rbcrevs = bytearray(self._rbcrevslen * _rbcrecsize) |
409 | 409 |
410 def branchinfo(self, rev, changelog=None): | 410 def branchinfo(self, rev): |
411 """Return branch name and close flag for rev, using and updating | 411 """Return branch name and close flag for rev, using and updating |
412 persistent cache.""" | 412 persistent cache.""" |
413 changelog = changelog or self._repo.changelog | 413 changelog = self._repo.changelog |
414 rbcrevidx = rev * _rbcrecsize | 414 rbcrevidx = rev * _rbcrecsize |
415 | 415 |
416 # avoid negative index, changelog.read(nullrev) is fast without cache | 416 # avoid negative index, changelog.read(nullrev) is fast without cache |
417 if rev == nullrev: | 417 if rev == nullrev: |
418 return changelog.branchinfo(rev) | 418 return changelog.branchinfo(rev) |
419 | 419 |
420 # if requested rev isn't allocated, grow and cache the rev info | 420 # if requested rev isn't allocated, grow and cache the rev info |
421 if len(self._rbcrevs) < rbcrevidx + _rbcrecsize: | 421 if len(self._rbcrevs) < rbcrevidx + _rbcrecsize: |
422 return self._branchinfo(rev, changelog=changelog) | 422 return self._branchinfo(rev) |
423 | 423 |
424 # fast path: extract data from cache, use it if node is matching | 424 # fast path: extract data from cache, use it if node is matching |
425 reponode = changelog.node(rev)[:_rbcnodelen] | 425 reponode = changelog.node(rev)[:_rbcnodelen] |
426 cachenode, branchidx = unpack_from( | 426 cachenode, branchidx = unpack_from( |
427 _rbcrecfmt, util.buffer(self._rbcrevs), rbcrevidx) | 427 _rbcrecfmt, util.buffer(self._rbcrevs), rbcrevidx) |
445 truncate = rbcrevidx + _rbcrecsize | 445 truncate = rbcrevidx + _rbcrecsize |
446 del self._rbcrevs[truncate:] | 446 del self._rbcrevs[truncate:] |
447 self._rbcrevslen = min(self._rbcrevslen, truncate) | 447 self._rbcrevslen = min(self._rbcrevslen, truncate) |
448 | 448 |
449 # fall back to slow path and make sure it will be written to disk | 449 # fall back to slow path and make sure it will be written to disk |
450 return self._branchinfo(rev, changelog=changelog) | 450 return self._branchinfo(rev) |
451 | 451 |
452 def _branchinfo(self, rev, changelog=None): | 452 def _branchinfo(self, rev): |
453 """Retrieve branch info from changelog and update _rbcrevs""" | 453 """Retrieve branch info from changelog and update _rbcrevs""" |
454 changelog = changelog or self._repo.changelog | 454 changelog = self._repo.changelog |
455 b, close = changelog.branchinfo(rev) | 455 b, close = changelog.branchinfo(rev) |
456 if b in self._namesreverse: | 456 if b in self._namesreverse: |
457 branchidx = self._namesreverse[b] | 457 branchidx = self._namesreverse[b] |
458 else: | 458 else: |
459 branchidx = len(self._names) | 459 branchidx = len(self._names) |
460 self._names.append(b) | 460 self._names.append(b) |
461 self._namesreverse[b] = branchidx | 461 self._namesreverse[b] = branchidx |
462 reponode = changelog.node(rev) | 462 reponode = changelog.node(rev) |
463 if close: | 463 if close: |
464 branchidx |= _rbccloseflag | 464 branchidx |= _rbccloseflag |
465 self._setcachedata(rev, reponode, branchidx, changelog) | 465 self._setcachedata(rev, reponode, branchidx) |
466 return b, close | 466 return b, close |
467 | 467 |
468 def setdata(self, branch, rev, node, close): | 468 def setdata(self, branch, rev, node, close): |
469 """add new data information to the cache""" | 469 """add new data information to the cache""" |
470 if branch in self._namesreverse: | 470 if branch in self._namesreverse: |
483 # | 483 # |
484 # Since we now have data in the cache, we need to drop this bypassing. | 484 # Since we now have data in the cache, we need to drop this bypassing. |
485 if r'branchinfo' in vars(self): | 485 if r'branchinfo' in vars(self): |
486 del self.branchinfo | 486 del self.branchinfo |
487 | 487 |
488 def _setcachedata(self, rev, node, branchidx, changelog=None): | 488 def _setcachedata(self, rev, node, branchidx): |
489 """Writes the node's branch data to the in-memory cache data.""" | 489 """Writes the node's branch data to the in-memory cache data.""" |
490 if rev == nullrev: | 490 if rev == nullrev: |
491 return | 491 return |
492 | |
493 changelog = changelog or self._repo.changelog | |
494 rbcrevidx = rev * _rbcrecsize | 492 rbcrevidx = rev * _rbcrecsize |
495 if len(self._rbcrevs) < rbcrevidx + _rbcrecsize: | 493 if len(self._rbcrevs) < rbcrevidx + _rbcrecsize: |
496 self._rbcrevs.extend('\0' * | 494 self._rbcrevs.extend('\0' * |
497 (len(changelog) * _rbcrecsize - | 495 (len(self._repo.changelog) * _rbcrecsize - |
498 len(self._rbcrevs))) | 496 len(self._rbcrevs))) |
499 pack_into(_rbcrecfmt, self._rbcrevs, rbcrevidx, node, branchidx) | 497 pack_into(_rbcrecfmt, self._rbcrevs, rbcrevidx, node, branchidx) |
500 self._rbcrevslen = min(self._rbcrevslen, rev) | 498 self._rbcrevslen = min(self._rbcrevslen, rev) |
501 | 499 |
502 tr = self._repo.currenttransaction() | 500 tr = self._repo.currenttransaction() |