Patchwork [6,of,6,RFC] radixlink: use C radixlink get implementation if available

login
register
mail settings
Submitter Jun Wu
Date May 22, 2017, 1:31 a.m.
Message ID <b69ca9116b2cae29fd18.1495416673@x1c>
Download mbox | patch
Permalink /patch/20813/
State Changes Requested
Headers show

Comments

Jun Wu - May 22, 2017, 1:31 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1495409961 25200
#      Sun May 21 16:39:21 2017 -0700
# Node ID b69ca9116b2cae29fd182c7bb545e59f16455d3f
# Parent  6916f2eede1507237cffdb62db1baff8ded04ea5
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r b69ca9116b2c
radixlink: use C radixlink get implementation if available
Augie Fackler - May 24, 2017, 9:26 p.m.
On Sun, May 21, 2017 at 06:31:13PM -0700, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1495409961 25200
> #      Sun May 21 16:39:21 2017 -0700
> # Node ID b69ca9116b2cae29fd182c7bb545e59f16455d3f
> # Parent  6916f2eede1507237cffdb62db1baff8ded04ea5
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r b69ca9116b2c
> radixlink: use C radixlink get implementation if available

Overall it sounds like this is worth doing, especially since it sounds
like it could also be used for things like speeding up node->rev
conversions later on.

I didn't go over the specifics of the implementation /too/ carefully,
but it looked reasonable. Care to do a v2 with timing information
added to this last commit?

>
> diff --git a/mercurial/radixlink.py b/mercurial/radixlink.py
> --- a/mercurial/radixlink.py
> +++ b/mercurial/radixlink.py
> @@ -12,6 +12,10 @@ import struct
>  from . import (
>      error,
> +    policy,
> +    util,
>  )
>
> +parsers = policy.importmod(r'parsers')
> +
>  def _enlarge(buf, size):
>      """enlarge a bytearray to at least given size"""
> @@ -134,4 +138,11 @@ class radixlink(object):
>          return result
>
> +    if util.safehasattr(parsers, 'radixlinkget'):
> +        # replace radixlink.get with a faster version
> +        def get(self, key):
> +            index = buffer(self.indexdata)
> +            link = buffer(self.linkdata)
> +            return parsers.radixlinkget(index, link, key)
> +
>      def insert(self, key, value):
>          """key: int, value: buffer"""
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Jun Wu - May 24, 2017, 9:35 p.m.
Excerpts from Augie Fackler's message of 2017-05-24 17:26:05 -0400:
> Overall it sounds like this is worth doing, especially since it sounds
> like it could also be used for things like speeding up node->rev
> conversions later on.
> 
> I didn't go over the specifics of the implementation /too/ carefully,
> but it looked reasonable. Care to do a v2 with timing information
> added to this last commit?

Sure.

For other reviewers looking into details of the format: A known issue is
memory alignment is not taken care of so reading 4 bytes may be problematic
on some platforms. They will be addressed in V2.

> [...]

Patch

diff --git a/mercurial/radixlink.py b/mercurial/radixlink.py
--- a/mercurial/radixlink.py
+++ b/mercurial/radixlink.py
@@ -12,6 +12,10 @@  import struct
 from . import (
     error,
+    policy,
+    util,
 )
 
+parsers = policy.importmod(r'parsers')
+
 def _enlarge(buf, size):
     """enlarge a bytearray to at least given size"""
@@ -134,4 +138,11 @@  class radixlink(object):
         return result
 
+    if util.safehasattr(parsers, 'radixlinkget'):
+        # replace radixlink.get with a faster version
+        def get(self, key):
+            index = buffer(self.indexdata)
+            link = buffer(self.linkdata)
+            return parsers.radixlinkget(index, link, key)
+
     def insert(self, key, value):
         """key: int, value: buffer"""