Skip to content

json: Serialise GapToJsonString directly in the kernel#36

Open
ChrisJefferson wants to merge 1 commit into
masterfrom
c-core
Open

json: Serialise GapToJsonString directly in the kernel#36
ChrisJefferson wants to merge 1 commit into
masterfrom
c-core

Conversation

@ChrisJefferson

Copy link
Copy Markdown
Member

GapToJsonString previously dispatched through the _GapToJsonStreamInternal GAP operation once per element, which dominated its runtime on record-heavy data. Serialise integers, booleans, strings, lists and records directly in the kernel instead, writing into a self-managed output buffer, and fall back to the GAP operation only for types the C code does not handle (floats, large integers, component objects, and user-installed methods).

The buffer tracks the string bag together with its length and capacity as plain integers, materialising the data pointer freshly after each growth, so no raw pointer is ever held across an allocation. Records are sorted by component name via SortPRecRNam before output, matching the previous Set(RecNames(...)) behaviour and keeping the emitted JSON byte-identical.

AI disclosure: this change was prepared with the assistance of Claude Code (Anthropic). Claude explored the existing serialiser, proposed and iterated on the C port and its GC-safety design, wrote the kernel and GAP code, and ran the regression, round-trip and garbage-collection stress tests. All work was done under the author's direction and review.

GapToJsonString previously dispatched through the _GapToJsonStreamInternal
GAP operation once per element, which dominated its runtime on record-heavy
data. Serialise integers, booleans, strings, lists and records directly in
the kernel instead, writing into a self-managed output buffer, and fall back
to the GAP operation only for types the C code does not handle (floats, large
integers, component objects, and user-installed methods).

The buffer tracks the string bag together with its length and capacity as
plain integers, materialising the data pointer freshly after each growth, so
no raw pointer is ever held across an allocation. Records are sorted by
component name via SortPRecRNam before output, matching the previous
Set(RecNames(...)) behaviour and keeping the emitted JSON byte-identical.

AI disclosure: this change was prepared with the assistance of Claude Code
(Anthropic). Claude explored the existing serialiser, proposed and iterated
on the C port and its GC-safety design, wrote the kernel and GAP code, and
ran the regression, round-trip and garbage-collection stress tests. All work
was done under the author's direction and review.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.50%. Comparing base (dcea64b) to head (7340a3f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #36      +/-   ##
==========================================
+ Coverage   96.42%   96.50%   +0.07%     
==========================================
  Files           6        6              
  Lines         140      143       +3     
==========================================
+ Hits          135      138       +3     
  Misses          5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant