This is an automated email from the ASF dual-hosted git repository.
kenhuuu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/master by this push:
new 531ce09b65 Speed up Python GraphBinary deserialization (#3493)
531ce09b65 is described below
commit 531ce09b651affa0f5fac9aed55d5416a0d4b6e0
Author: kirill-stepanishin <[email protected]>
AuthorDate: Mon Jul 6 14:03:46 2026 -0700
Speed up Python GraphBinary deserialization (#3493)
Add int-keyed deserializer dispatch to reader
Assisted-by: Claude Code:claude-opus-4-8
---
.../python/gremlin_python/structure/io/graphbinaryV4.py | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git
a/gremlin-python/src/main/python/gremlin_python/structure/io/graphbinaryV4.py
b/gremlin-python/src/main/python/gremlin_python/structure/io/graphbinaryV4.py
index 41843a33eb..23bb0ef083 100644
---
a/gremlin-python/src/main/python/gremlin_python/structure/io/graphbinaryV4.py
+++
b/gremlin-python/src/main/python/gremlin_python/structure/io/graphbinaryV4.py
@@ -79,6 +79,9 @@ class DataType(Enum):
NULL_BYTES = [DataType.null.value, 0x01]
+# null type code as a plain int, so the per-read null check skips the aenum
lookup
+_NULL = DataType.null.value
+
def _make_packer(format_string):
packer = struct.Struct(format_string)
@@ -149,6 +152,9 @@ class GraphBinaryReader(object):
if deserializer_map:
self.deserializers.update(deserializer_map)
self.pdt_registry = pdt_registry
+ # Mirror of self.deserializers keyed by int type code instead of
DataType.
+ # Avoids the per-read DataType(bt) call, whose aenum construction
negatively affects performance on large results.
+ self._deserializer_by_type_code = {dt.value: des.objectify for dt, des
in self.deserializers.items()}
def read_object(self, b):
if b is None:
@@ -160,11 +166,15 @@ class GraphBinaryReader(object):
def to_object(self, buff, data_type=None, nullable=True):
if data_type is None:
bt = uint8_unpack(buff.read(1))
- if bt == DataType.null.value:
+ if bt == _NULL:
if nullable:
buff.read(1)
return None
- result = self.deserializers[DataType(bt)].objectify(buff, self,
nullable)
+ try:
+ objectify = self._deserializer_by_type_code[bt]
+ except KeyError:
+ raise ValueError("%r is not a valid DataType" % bt) from None
+ result = objectify(buff, self, nullable)
else:
result = self.deserializers[data_type].objectify(buff, self,
nullable)
if self.pdt_registry is not None and isinstance(result,
ProviderDefinedType):