Skip to content

perf(json): skip legacy decoding for nonstring tokens - #1883

Merged
nahime0 merged 1 commit into
mainfrom
feat/json-trimmed-token-dispatch
Oct 19, 2026
Merged

nahime0 merged 1 commit into
mainfrom
feat/json-trimmed-token-dispatch

Conversation

@nahime0

@nahime0 nahime0 commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Structural JSON decoding already trims every token, but then calls the legacy string decoder for numbers, literals and containers as well. Dispatch these nonstring tokens using their saved raw slice. Validate string tokens first, then call the existing unescaper only from the string branch. Both AArch64 and x86_64 follow the same path.

A GDB counter on [[1,2,3,4],[5,6,7,8]] drops legacy unescaper calls from 11 to zero. Allocation/free counts remain 47/47. A 21-round Linux x86_64 comparison with two warmups, CPU11 affinity, isolated release-built bridge archives and concurrent-build guards changes the mixed workload JSON phase from 12.168 to 11.705 ms (1.040x by medians). The paired median speedup is 1.033x, with a bootstrap 95% interval of 1.021-1.039. All phases pass the 5% MAD gate. The whole-body difference does not have a conclusive paired interval, so this is a phase improvement, not a universal end-to-end claim. JSON representation and boxing are unchanged.

Validation: all 434 JSON codegen tests pass with the real PHP oracle enabled. The new mixed-token regression checks PHP results, both optimizer modes and a clean heap-debug summary. Focused emitter tests cover all five targets in direct and PIC modes. Assembly comments and git diff --check pass.

@github-actions github-actions Bot added area:runtime Touches runtime helpers, GC, ownership, or bridge runtimes. size:s Small pull request. target:linux-x86_64 Contains behavior specific to the Linux x86_64 target. type:feature Introduces new user-visible behavior or capabilities. labels Oct 18, 2026
@nahime0
nahime0 marked this pull request as ready for review October 18, 2026 21:44
@nahime0

nahime0 commented Oct 18, 2026

Copy link
Copy Markdown
Member Author

@greptileai please review the current head 6bf9bc0.

@greptile-apps

greptile-apps Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no actionable issues were found.

Summary

Both architecture emitters now skip __rt_json_decode for nonstring JSON tokens.

  • JSON decoding skips string unescaping for nonstring values.

No actionable issues found. git diff --check passed. Runtime tests were not run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Trim borrowed token"] --> B{"Token kind"}
  B -->|String| C["Validate whole token"]
  C -->|Valid| D["__rt_json_decode"]
  D --> E["Copy bytes into Mixed string"]
  C -->|Invalid| F["Return recorded error"]
  B -->|Number| G["Validate and convert raw slice"]
  B -->|Literal| H["Check raw token and box"]
  B -->|Container| I["Decode children from raw slice"]
Loading

Reviews (1) · Last reviewed commit: "perf(json): dispatch trimmed nonstring t..." · Reviewed by Greptile

@nahime0
nahime0 merged commit e26b086 into main Oct 19, 2026
192 checks passed
@nahime0
nahime0 deleted the feat/json-trimmed-token-dispatch branch October 19, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:runtime Touches runtime helpers, GC, ownership, or bridge runtimes. size:s Small pull request. target:linux-x86_64 Contains behavior specific to the Linux x86_64 target. type:feature Introduces new user-visible behavior or capabilities.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant