Mercurial > hg
view contrib/phab-clean.py @ 47120:7109a38830c9
dirstate-tree: Fold "tracked descendants" counter update in main walk
For the purpose of implementing `has_tracked_dir` (which means "has tracked
descendants) without an expensive sub-tree traversal, we maintaing a counter
of tracked descendants on each "directory" node of the tree-shaped dirstate.
Before this changeset, mutating or inserting a node at a given path would
involve:
* Walking the tree from root through ancestors to find the node or the spot
where to insert it
* Looking at the previous node if any to decide what counter update is needed
* Performing any node mutation
* Walking the tree *again* to update counters in ancestor nodes
When profiling `hg status` on a large repo, this second walk takes times
while loading a the dirstate from disk.
It turns out we have enough information to decide before he first tree walk
what counter update is needed. This changeset merges the two walks, gaining
~10% of the total time for `hg update` (in the same hyperfine benchmark as
the previous changeset).
---
Profiling was done by compiling with this `.cargo/config`:
[profile.release]
debug = true
then running with:
py-spy record -r 500 -n -o /tmp/hg.json --format speedscope -- \
./hg status -R $REPO --config experimental.dirstate-tree.in-memory=1
then visualizing the recorded JSON file in https://www.speedscope.app/
Differential Revision: https://phab.mercurial-scm.org/D10554
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Fri, 30 Apr 2021 14:22:14 +0200 |
parents | c102b704edb5 |
children | 6000f5b25c9b |
line wrap: on
line source
#!/usr/bin/env python3 # # A small script to automatically reject idle Diffs # # you need to set the PHABBOT_USER and PHABBOT_TOKEN environment variable for authentication from __future__ import absolute_import, print_function import datetime import os import sys import phabricator MESSAGE = """There seems to have been no activities on this Diff for the past 3 Months. By policy, we are automatically moving it out of the `need-review` state. Please, move it back to `need-review` without hesitation if this diff should still be discussed. :baymax:need-review-idle: """ PHAB_URL = "https://phab.mercurial-scm.org/api/" USER = os.environ.get("PHABBOT_USER", "baymax") TOKEN = os.environ.get("PHABBOT_TOKEN") NOW = datetime.datetime.now() # 3 months in seconds DELAY = 60 * 60 * 24 * 30 * 3 def get_all_diff(phab): """Fetch all the diff that the need review""" return phab.differential.query( status="status-needs-review", order="order-modified", paths=[('HG', None)], ) def filter_diffs(diffs, older_than): """filter diffs to only keep the one unmodified sin <older_than> seconds""" olds = [] for d in diffs: modified = int(d['dateModified']) modified = datetime.datetime.fromtimestamp(modified) d["idleFor"] = idle_for = NOW - modified if idle_for.total_seconds() > older_than: olds.append(d) return olds def nudge_diff(phab, diff): """Comment on the idle diff and reject it""" diff_id = int(d['id']) phab.differential.createcomment( revision_id=diff_id, message=MESSAGE, action="reject" ) if not USER: print( "not user specified please set PHABBOT_USER and PHABBOT_TOKEN", file=sys.stderr, ) elif not TOKEN: print( "not api-token specified please set PHABBOT_USER and PHABBOT_TOKEN", file=sys.stderr, ) sys.exit(1) phab = phabricator.Phabricator(USER, host=PHAB_URL, token=TOKEN) phab.connect() phab.update_interfaces() print('Hello "%s".' % phab.user.whoami()['realName']) diffs = get_all_diff(phab) print("Found %d Diffs" % len(diffs)) olds = filter_diffs(diffs, DELAY) print("Found %d old Diffs" % len(olds)) for d in olds: diff_id = d['id'] status = d['statusName'] modified = int(d['dateModified']) idle_for = d["idleFor"] msg = 'nudging D%s in "%s" state for %s' print(msg % (diff_id, status, idle_for)) # uncomment to actually affect phab nudge_diff(phab, d)