Commit Graph

22 Commits

Author SHA1 Message Date
Laurent Charignon
0cf109868d phase: compute phases in C
Previously, the phase computation would grow much slower as the oldest draft
commit in the repository grew older (which is very common in repos with evolve
on) and the number of commits increase.
By rewriting the computation in C we can speed it up from 700ms to 7ms on
a large repository whose oldest draft commit is a year old.
2015-03-24 11:00:09 -07:00
Matt Mackall
99e9f5ee02 manifest: move C bool polyfill into util.h 2015-03-25 14:16:10 -05:00
Augie Fackler
78ce05f424 util: add getbefloat64
As far as I can tell, this is wrong. double's format isn't strictly
specified in the C standard, but the wikipedia article implies that
platforms implementing optional Annex F "IEC 60559 floating-point
arithmetic" will work correctly.

My local C experts believe doing *((double *) &t) is a strict aliasing
violation, and that using a union is also one. Doing memcpy appears to
be the least-undefined behavior possible.
2015-02-03 13:17:21 -05:00
Augie Fackler
8ef7d1d411 util: add getbe{u,}int16 utility methods 2015-01-20 14:09:57 -05:00
André Sintzoff
e960b46a33 util.h: declare dirstateTupleType variable instead of defining it
The definition is already in parsers.c

This patch avoids, at least on Mac OS X 10.6.8, build issue since 00dd020bc772
2014-07-03 19:05:04 +02:00
Siddharth Agarwal
f40a94a790 parsers: inline fields of dirstate values in C version
Previously, while unpacking the dirstate we'd create 3-4 new CPython objects
for most dirstate values:

- the state is a single character string, which is pooled by CPython
- the mode is a new object if it isn't 0 due to being in the lookup set
- the size is a new object if it is greater than 255
- the mtime is a new object if it isn't -1 due to being in the lookup set
- the tuple to contain them all

In some cases such as regular hg status, we actually look at all the objects.
In other cases like hg add, hg status for a subdirectory, or hg status with the
third-party hgwatchman enabled, we look at almost none of the objects.

This patch eliminates most object creation in these cases by defining a custom
C struct that is exposed to Python with an interface similar to a tuple. Only
when tuple elements are actually requested are the respective objects created.

The gains, where they're expected, are significant. The following tests are run
against a working copy with over 270,000 files.

parse_dirstate becomes significantly faster:

$ hg perfdirstate
before: wall 0.186437 comb 0.180000 user 0.160000 sys 0.020000 (best of 35)
after:  wall 0.093158 comb 0.100000 user 0.090000 sys 0.010000 (best of 95)

and as a result, several commands benefit:

$ time hg status  # with hgwatchman enabled
before: 0.42s user 0.14s system 99% cpu 0.563 total
after:  0.34s user 0.12s system 99% cpu 0.471 total

$ time hg add new-file
before: 0.85s user 0.18s system 99% cpu 1.033 total
after:  0.76s user 0.17s system 99% cpu 0.931 total

There is a slight regression in regular status performance, but this is fixed
in an upcoming patch.
2014-05-27 14:27:41 -07:00
Siddharth Agarwal
4500805b25 util.h: backout cb07828e14e0 and 7d902369e960 for big-endian breakage
getbe32 and putbe32 need to behave differently on big-endian and little-endian
systems. On big-endian ones, they should be roughly equivalent to the identity
function with a cast, but on little-endian ones they should reverse the order
of the bytes. That is achieved by the original definition, but
__builtin_bswap32 and _byteswap_ulong, as the names suggest, swap bytes around
unconditionally.

There was no measurable performance improvement, so there's no point adding
extra complexity with even more ifdefs for endianncess.
2013-09-30 12:36:26 -07:00
Siddharth Agarwal
57e4e00df6 util.h: fix gcc version checking
gcc doesn't have a predefined GCC_VERSION macro.
2013-09-19 09:45:00 -07:00
Wei, Elson
f78ba81b28 util.h: getbe32() and putbe32() use intrinsic function to improve performance
Refer to https://bugzilla.mozilla.org/show_bug.cgi?id=351557. It can improve
byte-swapping performance by intrinsic function.
2013-09-14 11:22:34 +08:00
Wei, Elson
2400e9cc93 util.h: add stdint basic type definitions
MS C compiler v15 doesn't have stdint.h. Add basic int types those are defined
in stdint.h.
2013-09-13 09:54:43 +08:00
Bryan O'Sullivan
a150198558 store: implement fncache basic path encoding in C
(This is not yet enabled; it will be turned on in a followup patch.)

The path encoding performed by fncache is complex and (perhaps
surprisingly) slow enough to negatively affect the overall performance
of Mercurial.

For a short path (< 120 bytes), the Python code can be reduced to a fairly
tractable state machine that either determines that nothing needs to be
done in a single pass, or performs the encoding in a second pass.

For longer paths, we avoid the more complicated hashed encoding scheme
for now, and fall back to Python.

Raw performance: I measured in a repo containing 150,000 files in its tip
manifest, with a median path name length of 57 bytes, and 95th percentile
of 96 bytes.

In this repo, the Python code takes 3.1 seconds to encode all path
names, while the hybrid C-and-Python code (called from Python) takes
0.21 seconds, for a speedup of about 14.

Across several other large repositories, I've measured the speedup from
the C code at between 26x and 40x.

For path names above 120 bytes where we must fall back to Python for
hashed encoding, the speedup is about 1.7x.  Thus absolute performance
will depend strongly on the characteristics of a particular repository.
2012-09-18 15:42:19 -07:00
Adrian Buehlmann
f5ca6da4d6 parser: use PyInt_FromSsize_t in index_stats
Eliminates

  mercurial/parsers.c(515) : warning C4244: 'function' : conversion from
  'Py_ssize_t' to 'long', possible loss of data
  mercurial/parsers.c(520) : warning C4244: 'function' : conversion from
  'Py_ssize_t' to 'long', possible loss of data
  mercurial/parsers.c(521) : warning C4244: 'function' : conversion from
  'Py_ssize_t' to 'long', possible loss of data

when compiling for Windows x64 target using the Microsoft compiler.

PyInt_FromSsize_t does not exist for Python 2.4 and earlier, so we define a
fallback in util.h to use PyInt_FromLong when compiling for Python 2.4.
2012-05-09 09:58:50 +02:00
Matt Mackall
0fa9895915 util.h: replace ntohl/htonl with get/putbe32 2012-04-16 11:26:00 -05:00
Matt Mackall
0ba5fb4cce util.h: more Python 2.4 fixes 2012-04-10 16:53:29 -05:00
Matt Mackall
fd4256c9b1 util.h: unify some common platform tweaks 2012-04-10 12:07:14 -05:00
Matt Mackall
935d420846 util.h: move Py_ssize_t bits from mpatch.c 2012-04-10 12:07:09 -05:00
Matt Mackall
afeb0ce18a util.h: add a typedef for Py_ssize_t with Python 2.4 2012-04-08 22:17:51 -05:00
Martin Geisler
a76e121863 backout of e4cb9628354c
Matt and a majority of crew did not like this approach.
2011-01-27 11:15:08 +01:00
Martin Geisler
d23e1973c2 specify C indention style using Emacs file local variables 2011-01-26 12:05:01 +01:00
Renato Cunha
b985656666 util.h: Defined macros for working "with" PyStrings in py3k.
PyString* functions are defined as PyUnicode* to permit correct compilation in
both python 2.x and 3.x.
2010-07-02 16:21:40 -03:00
Renato Cunha
d3325144cd util.h: Add a PyInt_AsLong definition for usage in the inotify module. 2010-07-02 16:21:38 -03:00
Renato Cunha
9dcf925abb util.h: Utility macros for handling different Python APIs.
If we are in py3k, a IS_PY3K symbol is defined. Apart from that, byte strings
use the API defined in Python 2.6+ (_?PyBytes_.*). For Python < 2.6, the bytes
API is defined accordingly for mercurial usage (shameless copy from
bytesobject.h from Python's code). Some macros were backported from 2.6, as
inspired by rPath's pycompat.h.
2010-06-15 19:49:56 -03:00