##// END OF EJS Templates
rust: peek_mut optim for lazy ancestors...
rust: peek_mut optim for lazy ancestors This is one of the two optimizations that are also present in the Python code: replacing pairs of pop/push on the BinaryHeap by single updates, hence having it under the hood maintain its consistency (sift) only once. On Mozilla central, the measured gain (see details below) is around 7%. Creating the PeekMut object by calling peek_mut() right away instead of peek() first is less efficient (gain is only 4%, stats not included). Our interpretation is that its creation has a cost which is vasted in the cases where it ends by droping the value (Peekmut::pop() just does self.heap.pop() anyway). On the other hand, the immutable peek() is very fast: it's just taking a reference in the underlying vector. The Python version still has another optimization: if parent(current) == current-1, then the heap doesn't need to maintain its consistency, since we already know that it's bigger than all the others in the heap. Rust's BinaryHeap doesn't allow us to mutate its biggest element with no housekeeping, but we tried it anyway, with a copy of the BinaryHeap implementation with a dedicaded added method: it's not worth the technical debt in our opinion (we measured only a further 1.6% improvement). One possible explanation would be that the sift is really fast anyway in that case, whereas it's not in the case of Python, because it's at least partly done in slow Python code. Still it's possible that replacing BinaryHeap by something more dedicated to discrete ordered types could be faster. Measurements on mozilla-central: Three runs of 'hg perfancestors' on the parent changeset: Moyenne des médianes: 0.100587 ! wall 0.100062 comb 0.100000 user 0.100000 sys 0.000000 (best of 98) ! wall 0.135804 comb 0.130000 user 0.130000 sys 0.000000 (max of 98) ! wall 0.102864 comb 0.102755 user 0.099286 sys 0.003469 (avg of 98) ! wall 0.101486 comb 0.110000 user 0.110000 sys 0.000000 (median of 98) ! wall 0.096804 comb 0.090000 user 0.090000 sys 0.000000 (best of 100) ! wall 0.132235 comb 0.130000 user 0.120000 sys 0.010000 (max of 100) ! wall 0.100258 comb 0.100300 user 0.096000 sys 0.004300 (avg of 100) ! wall 0.098384 comb 0.100000 user 0.100000 sys 0.000000 (median of 100) ! wall 0.099925 comb 0.100000 user 0.100000 sys 0.000000 (best of 98) ! wall 0.133518 comb 0.140000 user 0.130000 sys 0.010000 (max of 98) ! wall 0.102381 comb 0.102449 user 0.098265 sys 0.004184 (avg of 98) ! wall 0.101891 comb 0.090000 user 0.090000 sys 0.000000 (median of 98) Mean of the medians: 0.100587 On the present changeset: ! wall 0.091344 comb 0.090000 user 0.090000 sys 0.000000 (best of 100) ! wall 0.122728 comb 0.120000 user 0.110000 sys 0.010000 (max of 100) ! wall 0.093268 comb 0.093300 user 0.089300 sys 0.004000 (avg of 100) ! wall 0.092567 comb 0.100000 user 0.090000 sys 0.010000 (median of 100) ! wall 0.093294 comb 0.080000 user 0.080000 sys 0.000000 (best of 100) ! wall 0.144887 comb 0.150000 user 0.140000 sys 0.010000 (max of 100) ! wall 0.097708 comb 0.097700 user 0.093400 sys 0.004300 (avg of 100) ! wall 0.094980 comb 0.100000 user 0.090000 sys 0.010000 (median of 100) ! wall 0.091262 comb 0.090000 user 0.080000 sys 0.010000 (best of 100) ! wall 0.123772 comb 0.130000 user 0.120000 sys 0.010000 (max of 100) ! wall 0.093188 comb 0.093200 user 0.089300 sys 0.003900 (avg of 100) ! wall 0.092364 comb 0.100000 user 0.090000 sys 0.010000 (median of 100) Mean of the medians is 0.0933 Differential Revision: https://phab.mercurial-scm.org/D5358

File last commit:

r40329:c303d65d default
r40847:e13ab4ac default
Show More
purge.py
111 lines | 3.9 KiB | text/x-python | PythonLexer
Emanuele Aina
Move back the purge extension in hgext
r4311 # Copyright (C) 2006 - Marco Barisione <marco@barisione.org>
#
Matt Mackall
urls: bulk-change primary website URLs
r26421 # This is a small extension for Mercurial (https://mercurial-scm.org/)
Emanuele Aina
Move back the purge extension in hgext
r4311 # that removes files not known to mercurial
#
Martin Geisler
purge: wrap docstrings at 70 characters
r9270 # This program was inspired by the "cvspurge" script contained in CVS
# utilities (http://www.red-bean.com/cvsutils/).
Emanuele Aina
Move back the purge extension in hgext
r4311 #
# For help on the usage of "hg purge" use:
# hg help purge
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
Martin Geisler
Remove FSF mailing address from GPL headers...
r15782 # along with this program; if not, see <http://www.gnu.org/licenses/>.
Emanuele Aina
Move back the purge extension in hgext
r4311
Dirkjan Ochtman
extensions: change descriptions for extensions providing a few commands
r8934 '''command to delete untracked files from the working directory'''
timeless
purge: use absolute_import
r28382 from __future__ import absolute_import
Dirkjan Ochtman
help: add/fix docstrings for a bunch of extensions
r8873
Yuya Nishihara
py3: move up symbol imports to enforce import-checker rules...
r29205 from mercurial.i18n import _
timeless
purge: use absolute_import
r28382 from mercurial import (
Yuya Nishihara
commands: move templates of common command options to cmdutil (API)...
r32375 cmdutil,
Gregory Szorc
merge: move purge logic from extension...
r39499 merge as mergemod,
Augie Fackler
purge: apply byteskwargs to opts, fixing all python3 issues here...
r36589 pycompat,
Yuya Nishihara
registrar: move cmdutil.command to registrar module (API)...
r32337 registrar,
timeless
purge: use absolute_import
r28382 scmutil,
)
Emanuele Aina
Move back the purge extension in hgext
r4311
Adrian Buehlmann
purge: use cmdutil.command decorator
r14310 cmdtable = {}
Yuya Nishihara
registrar: move cmdutil.command to registrar module (API)...
r32337 command = registrar.command(cmdtable)
Augie Fackler
extensions: change magic "shipped with hg" string...
r29841 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
Augie Fackler
extensions: document that `testedwith = 'internal'` is special...
r25186 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
# be specifying the version(s) of Mercurial they are tested with, or
# leave the attribute unspecified.
Augie Fackler
extensions: change magic "shipped with hg" string...
r29841 testedwith = 'ships-with-hg-core'
Adrian Buehlmann
purge: use cmdutil.command decorator
r14310
@command('purge|clean',
[('a', 'abort-on-err', None, _('abort if an error occurs')),
('', 'all', None, _('purge ignored files too')),
Ben Kehoe
purge: add options for deleting only files or only directories
r21853 ('', 'dirs', None, _('purge empty directories')),
('', 'files', None, _('purge files')),
Adrian Buehlmann
purge: use cmdutil.command decorator
r14310 ('p', 'print', None, _('print filenames instead of deleting them')),
('0', 'print0', None, _('end filenames with NUL, for use with xargs'
' (implies -p/--print)')),
Yuya Nishihara
commands: move templates of common command options to cmdutil (API)...
r32375 ] + cmdutil.walkopts,
rdamazio@google.com
help: assigning categories to existing commands...
r40329 _('hg purge [OPTION]... [DIR]...'),
helpcategory=command.CATEGORY_MAINTENANCE)
Matt Mackall
purge: eliminate dopurge
r6573 def purge(ui, repo, *dirs, **opts):
Benjamin Pollack
1 file changed, 7 insertions(+), 9 deletions(-)...
r7605 '''removes files not tracked by Mercurial
Matt Mackall
purge: eliminate dopurge
r6573
Martin Geisler
purge: wrap docstrings at 70 characters
r9270 Delete files not known to Mercurial. This is useful to test local
and uncommitted changes in an otherwise-clean source tree.
Matt Mackall
purge: eliminate dopurge
r6573
Ben Kehoe
purge: add options for deleting only files or only directories
r21853 This means that purge will delete the following by default:
Martin Geisler
purge: fix formatting of lists with proper reST markup
r9215
Martin Geisler
Use hg role in help strings
r10973 - Unknown files: files marked with "?" by :hg:`status`
Martin Geisler
purge: wrap docstrings at 70 characters
r9270 - Empty directories: in fact Mercurial ignores directories unless
they contain files under source control management
Martin Geisler
purge: fix formatting of lists with proper reST markup
r9215
Matt Mackall
purge: eliminate dopurge
r6573 But it will leave untouched:
Martin Geisler
purge: fix formatting of lists with proper reST markup
r9215
- Modified and unmodified tracked files
- Ignored files (unless --all is specified)
Martin Geisler
Use hg role in help strings
r10973 - New files added to the repository (with :hg:`add`)
Matt Mackall
purge: eliminate dopurge
r6573
Ben Kehoe
purge: add options for deleting only files or only directories
r21853 The --files and --dirs options can be used to direct purge to delete
only files, only directories, or both. If neither option is given,
both will be deleted.
Matt Mackall
purge: eliminate dopurge
r6573 If directories are given on the command line, only files in these
directories are considered.
Martin Geisler
purge: wrap docstrings at 70 characters
r9270 Be careful with purge, as you could irreversibly delete some files
you forgot to add to the repository. If you only want to print the
list of files that this program would delete, use the --print
option.
Matt Mackall
purge: eliminate dopurge
r6573 '''
Augie Fackler
purge: apply byteskwargs to opts, fixing all python3 issues here...
r36589 opts = pycompat.byteskwargs(opts)
Gregory Szorc
merge: move purge logic from extension...
r39499
Gregory Szorc
purge: use opts.get()...
r29222 act = not opts.get('print')
Matt Mackall
purge: cleanup...
r6757 eol = '\n'
Gregory Szorc
purge: use opts.get()...
r29222 if opts.get('print0'):
Matt Mackall
purge: cleanup...
r6757 eol = '\0'
act = False # --print0 implies --print
Gregory Szorc
merge: move purge logic from extension...
r39499
Gregory Szorc
purge: use opts.get()...
r29222 removefiles = opts.get('files')
removedirs = opts.get('dirs')
Gregory Szorc
merge: move purge logic from extension...
r39499
Ben Kehoe
purge: add options for deleting only files or only directories
r21853 if not removefiles and not removedirs:
removefiles = True
removedirs = True
Emanuele Aina
Move back the purge extension in hgext
r4311
Gregory Szorc
merge: move purge logic from extension...
r39499 match = scmutil.match(repo[None], dirs, opts)
Emanuele Aina
Move back the purge extension in hgext
r4311
Gregory Szorc
merge: move purge logic from extension...
r39499 paths = mergemod.purge(
repo, match, ignored=opts.get('all', False),
removeemptydirs=removedirs, removefiles=removefiles,
abortonerror=opts.get('abort_on_err'),
noop=not act)
Emanuele Aina
Move back the purge extension in hgext
r4311
Gregory Szorc
merge: move purge logic from extension...
r39499 for path in paths:
if not act:
ui.write('%s%s' % (path, eol))