Commit Graph

31 Commits

Author SHA1 Message Date
Joerg Sonnenberger
b1f2bd10ac phases: drop the list with phase of each rev, always comput phase sets
Change the C implementation of phasecache.loadphaserevs to provide only
the sets for draft and secret phase as well as the number of revisions
seen.

Change the pure Python implementation of the same functino to compute
the sets instead of the list of phases for each revision.

Change phasecache.phase to check the phase sets and assume public if the
revision is in neither draft nor secret set. This is computationally
slightly more expensive.

Change phasecache.getrevset for public() based queries to compute the
set of non-matching revisions and return the result as filtered
fullreposet. A shortcut is taken when no draft or secret revision
exists.

Bump the module version for the changed interface contract.

Overall, this saves around 16 Bytes per revision whenever the phasecache
is used, for the test case in issue5691 it is around 3MB. getrevset()
for a large repository is around 13% slower here, that seems an
acceptable trade off. Performance impact for phase() should be similar.

Differential Revision: https://phab.mercurial-scm.org/D1606
2017-12-06 15:46:41 +01:00
Augie Fackler
7ca1f09f81 parsers: allow clang-format here
# skip-blame because parsers.c is mechanically rewritten by
clang-format with no semantic change.

Differential Revision: https://phab.mercurial-scm.org/D1170
2017-10-16 14:53:57 -04:00
Augie Fackler
90df42e97c cext: add /* header */ comment to all PyVarObject_HEAD_INIT() calls
This gives clang-format the right notion about formatting these struct
initializers, therefore allowing us to automatically format several
additional files.

# skip-blame because this is just a content-free comment addition

Differential Revision: https://phab.mercurial-scm.org/D1169
2017-10-16 14:49:35 -04:00
Augie Fackler
9ae9ebef63 parsers: protect some case-folding tables from clang-format
We want a slightly weird format here so that it's easier to read, but
in order to preserve that we need to disable clang-format.

Differential Revision: https://phab.mercurial-scm.org/D1168
2015-04-21 16:02:23 -04:00
Augie Fackler
bad97ff7fe util: add clang-format control comment around struct and format macro
clang-format is not a fan of PyObject_HEAD.

Differential Revision: https://phab.mercurial-scm.org/D1031
2017-10-04 11:02:44 -04:00
Gregory Szorc
ce576c3b19 cext: wrap before brace for functions
This is our prevailing style.

Differential Revision: https://phab.mercurial-scm.org/D910
2017-10-02 19:28:41 +01:00
Gregory Szorc
5397128d04 cext: put case statements on separate line
This seems to be the prevailing style, even though it is a bit more
verbose for very simple switch statements.

Differential Revision: https://phab.mercurial-scm.org/D909
2017-10-02 19:09:52 +01:00
Gregory Szorc
a9a915a1bf cext: reorder #include
We mostly abide by this style.

In one case, a blank line was inserted to prevent a local
`#include "file"` from coming before a `#include <file>`.

Differential Revision: https://phab.mercurial-scm.org/D908
2017-10-02 19:06:00 +01:00
Gregory Szorc
1e024e0e3a cext: move braces for control statements to same line
This seems to be the prevailing style in the code by a wide margin.

Differential Revision: https://phab.mercurial-scm.org/D907
2017-10-02 19:02:43 +01:00
Yuya Nishihara
9b22314380 encoding: check overflow while calculating size of JSON escape buffer
The minimum input size to exploit is ~682MB (= INT_MAX / len('\\u0000') * 2)
on 32bit system, which isn't easy to achieve using Python str in 2GB process
address space, but probably doable.
2017-08-31 21:56:40 +09:00
Yuya Nishihara
a22ffac20b encoding: add function to test if a str consists of ASCII characters
Most strings are ASCII. Let's optimize for it.

Using uint64_t is slightly faster than uint32_t on 64bit system, but there
isn't huge difference.
2017-04-23 12:59:42 +09:00
Yuya Nishihara
569f77ac30 encoding: add fast path of jsonescape() (issue5533)
This isn't highly optimized as it copies characters one by one, but seems
reasonably simple and not slow.

  (with mercurial repo)
  $ export HGRCPATH=/dev/null HGPLAIN=
  $ hg log --time --config experimental.stabilization=all -Tjson > /dev/null

  (original)
  time: real 6.830 secs (user 6.740+0.000 sys 0.080+0.000)
  time: real 6.690 secs (user 6.650+0.000 sys 0.040+0.000)
  time: real 6.700 secs (user 6.640+0.000 sys 0.060+0.000)

  (this patch)
  time: real 5.630 secs (user 5.550+0.000 sys 0.070+0.000)
  time: real 5.700 secs (user 5.650+0.000 sys 0.050+0.000)
  time: real 5.690 secs (user 5.640+0.000 sys 0.050+0.000)
2017-04-23 14:47:52 +09:00
Yuya Nishihara
9eb2a84457 cext: move PyInt macros to charencode.c properly
Python3 build was broken at 49826c21bae5.
2017-08-14 13:35:26 +09:00
Yuya Nishihara
665cbeddba cext: modernize charencode.c to use Py_ssize_t 2017-07-31 22:58:06 +09:00
Yuya Nishihara
b32d207c09 cext: factor out header for charencode.c
This merges a part of util.h with the header which should exist for
charencode.c.
2017-05-21 14:23:22 +09:00
Yuya Nishihara
20afdd710d cext: split character encoding functions to new compilation unit
This extracts charencode.c from parsers.c, which seems big enough for me
to hesitate to add new JSON functions. Still charencode.o is linked to
parsers.so to avoid duplication of binary codes.
2017-07-31 22:28:27 +09:00
Yuya Nishihara
7f424270a8 cext: move _dict_new_presized() to header
Prepares for splitting encoding functions from parsers.c.
2017-07-31 22:12:24 +09:00
Sune Foldager
dca90c364e parsers: fix invariant bug in find_deepest (issue5623)
find_deepest is used to find the "best" ancestors given a list. In the main
loop it keeps an invariant called 'ninteresting' which is supposed to contain
the number of non-zero entries in the 'interesting' array. This invariant is
incorrectly maintained, however, which leads the the algorithm returning an
empty result for certain graphs. This has been fixed.

Also, the 'interesting' array is supposed to fit 2^ancestors values, but is
incorrectly allocated to twice that size. This has been fixed as well.

The tests in test-ancestor.py compare the Python and C versions of the code,
and report the error correctly, since the Python version works correct. Even
so, I have added an additional test against the expected result, in the event
that both algorithms have an identical error in the future.

This fixes issue5623.
2017-07-14 13:48:17 +02:00
Gregory Szorc
c8dd79852f revlog: address review feedback for deltachain C implementation
* Scope of "value" is reduced
* index_baserev() is documented
* Error is no longer redundantly set for -2 return values
* Error values are compared <= -2 instead of == -2 to protect
  against odd failure scenarios
2017-07-01 19:35:17 -07:00
Gregory Szorc
c45a2cb5ab revlog: C implementation of delta chain resolution
I've seen revlog._deltachain() appear in a number of performance
profiles. I suspect there are 2 reasons for this:

1. Delta chain resolution performs many index lookups, thus triggering
   population of index tuples. Creating possibly tens of thousands of
   PyObject will have overhead.
2. Delta chain resolution is a tight loop.

By moving delta chain resolution to C, we can defer instantiation
of full index entry tuples and make the loop faster courtesy of
not running in Python.

We can measure the impact to delta chain resolution via
`hg perflogrevision` using the mozilla-central repo with a recent
manifest having delta chain length of 33726:

$ hg perfrevlogrevision -m 364895
! full
! wall 0.367585 comb 0.370000 user 0.340000 sys 0.030000 (best of 27)
! wall 0.357581 comb 0.360000 user 0.350000 sys 0.010000 (best of 28)
! deltachain
! wall 0.010644 comb 0.010000 user 0.010000 sys 0.000000 (best of 270)
! wall 0.000292 comb 0.000000 user 0.000000 sys 0.000000 (best of 8729)

$ hg perfrevlogrevision --cache -m 364895
! deltachain
! wall 0.003904 comb 0.000000 user 0.000000 sys 0.000000 (best of 712)
! wall 0.000284 comb 0.000000 user 0.000000 sys 0.000000 (best of 9926)

The first test measures savings from both not instantiating index
entries and moving to C. The second test (which doesn't clear the
index caches) essentially isolates the benefits of moving from Python
to C. It still shows a 13.7x speedup (versus 36.4x). And there are
multiple milliseconds of savings within the critical path for resolving
revision data. I think that justifies the existence of C code.

A more striking example of the benefits of this change can be
demonstrated by timing `hg debugdeltachain -m` for the mozilla-central
repo:

$ time hg debugdeltachain -m > /dev/null
before:        1057.4s
after:          503.3s
PyPy2.7 5.8.0:  220.0s

It's worth noting that the C code isn't as optimal as it could be.
We're still instantiating a new PyObject for every revision. A future
optimization would be to reuse the PyObject on the cached index tuple.
We could potentially also get wins by using a memory array of raw
integers. There is also room for a delta chain cache on revlog
instances. Of course, the best optimization is to implement revlog
reading outside of Python so Python doesn't need to be concerned
about the relatively expensive index entries and operations on them.
2017-06-25 12:41:34 -07:00
Yuya Nishihara
c8c29352a4 cext: mark constant variables 2017-05-21 13:41:01 +09:00
Yuya Nishihara
79ebd14e1e cext: move util.h to cext tree
Since util.h isn't useful in plain C module, it should be placed in CPython
extension directory.
2017-05-21 13:35:19 +09:00
Yuya Nishihara
0174b4e600 cext: move back finalization of dirstateTupleType where it should be 2017-05-21 13:31:27 +09:00
Gregory Szorc
9e19911eaa cext: extract revlog/index parsing code to own C file
parsers.c is ~3000 lines and ~2/3 of it is related to the revlog
index type.

We already have separate C source files for directory utilities
and manifest parsing. I think the quite unwieldy revlog/index
parsing code should be self-contained as well.

I performed the extraction as a file copy then removed content
from both sides in order to preserve file history and blame.

As part of this, I also had to move the hexdigit table and
function to a shared header since it is used by both parsers.c
and revlog.c

# no-check-commit
2017-05-20 14:01:05 -07:00
Yuya Nishihara
4563e16232 parsers: switch to policy importer
# no-check-commit
2016-08-13 12:23:56 +09:00
Yuya Nishihara
5fe7742660 mpatch: switch to policy importer 2016-08-13 12:18:58 +09:00
Yuya Nishihara
6130be9a6c diffhelpers: switch to policy importer
# no-check-commit
2016-08-13 12:15:49 +09:00
Yuya Nishihara
50b316b748 bdiff: switch to policy importer
# no-check-commit
2016-08-13 12:12:50 +09:00
Yuya Nishihara
a9b78ccb21 base85: switch to policy importer 2016-08-13 12:08:23 +09:00
Yuya Nishihara
70995f9aa9 osutil: switch to policy importer
"make clean" is recommended to test this change, though C API compatibility
should be preserved.
2016-08-12 11:35:17 +09:00
Yuya Nishihara
276d62703a policy: add "cext" package which will host CPython extension modules
I'm going to restructure cext/pure modules and get rid of our hgimporter
hack. C extension modules will be moved to cext/ directory so old and new
compiled modules can coexist in development tree. This is necessary to
run 'hg bisect' without recompiling.

New extension modules will be loaded by an importer function:

  base85 = policy.importmod('base85')  # select pure.base85 or cext.base85

This will also allow us to split cffi from pure modules, which is currently
difficult because pure modules can't be imported by name.
2016-08-12 11:06:14 +09:00