Skip to content

native: skip the decode hook when a reply holds no tagged value - #152

Merged
tae898 merged 1 commit into
mainfrom
perf/151-decode-without-hook
Oct 30, 2026
Merged

tae898 merged 1 commit into
mainfrom
perf/151-decode-without-hook

Conversation

@tae898

@tae898 tae898 commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Closes #151

codec.loads now returns json.loads(text) when the reply text does not contain the escaped tag \u0001, and keeps the hook path otherwise. NativeCodec.quote escapes every character below 0x20, so a tagged value always puts that escape in the text: the shortcut can never skip a tagged value. A false positive (a string or a key that merely contains U+0001) only takes the existing hook path.

Measurements are in #151 (untimed micro-benchmark on the laptop measurement lane): about 1 us less per one-row reply, 2.315 us with the hook against 1.329 us without. Who it serves: users of the default arcadedb (native) package doing point and small range reads. No API change.

Tests (tests/test_native_codec_loads.py, pure codec, no database):

  • tag-free replies of 0, 1, 1000 rows and every JSON value kind decode equal to the hook path;
  • the hook is not called for a tag-free reply (fails on main, where loads always calls _hook);
  • the float-tail argument does not change a tag-free reply;
  • a tagged date is still restored, a string holding U+0001 comes back unchanged, a column named like the tag is kept.

The end-to-end transport tests (test_native_result_transport.py and the rest of the suite) run on every leg in CI.

🤖 Generated with Claude Code

codec.loads ran json.loads(text, object_hook=_hook), a Python call per decoded
object, for every reply. NativeCodec.quote escapes every character below 0x20,
so a tagged value always puts the escaped tag in the text; when it is absent the
hook changes nothing and is skipped. Untimed micro-benchmark: 2.315 -> 1.329 us
for a one-row reply. A string or key containing U+0001 still takes the hook path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tae898
tae898 merged commit f9804d8 into main Oct 30, 2026
36 checks passed
@tae898
tae898 deleted the perf/151-decode-without-hook branch October 30, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native reply decode runs the object_hook on every object, also when the reply holds no tagged value

1 participant