Skip to content

perf(jit): lower every string relation through one content compare - #315

Merged
siyul-park merged 2 commits into
mainfrom
perf/jit-string-compare
Nov 10, 2026
Merged

siyul-park merged 2 commits into
mainfrom
perf/jit-string-compare

Conversation

@siyul-park

Copy link
Copy Markdown
Owner

Summary

Part B of the string review (plan: one model, standard pieces). Strings stay what they are: an immutable Go string per heap ref, compared by content, with append-only concat storage and constants deduplicated at load. There is no interning and no rope. This PR removes the inconsistencies the review found:

  1. One native compare for six relations. STRING_EQ/NE lowered natively, but LT/GT/LE/GE bridged, although all six are one byte-wise content comparison. stringCompare replaces stringEq and leaves the flags of left against right:
    • from the first differing word, byte-reversed to big-endian;
    • else from the first differing byte;
    • else from the lengths.
      Each relation reads the flags with its unsigned condition (EQ/NE/LO/HI/LS/HS) through m.set, so a following branch fuses on the flags. Equality still leaves early on unequal lengths. Every path into out arrives straight after its CMP, and CBZ keeps the flags. Only loads, so no Go pointer is written.
  2. Units stated in instruction-set.md: string.len is the UTF-8 byte length; string.new_utf32/encode_utf32 use code points; ordering is unsigned byte-wise. Threaded already behaves this way; it was just undocumented.
  3. Dead generator branch removed. For a KindAny CONST_GET, internal/codegen/slot.go emitted i.intern(...), a method that no longer exists. make generate leaves threaded.go unchanged, so the branch never generated.

Evidence

  • TestMachine_Lower: six relation rows. Red before the change (expected len=56 actual len=52).
  • TestWithThreshold "compares strings and refs natively": all six relations over 14 new pairs, with results equal to threaded. The pairs cover:
    • prefixes both ways and a word-long prefix;
    • differences inside and after the first word, and in tail bytes;
    • "é" vs "z" and high bytes within a word;
    • empty strings.
      Red before: the ordering relations never went native.
  • A non-string operand traps as threaded does for LT–GE, with zero bridges. Red before: 47 bridges.
  • Two tests used STRING_LT as their "unlowered op" and now use STRING_CONCAT. They are not weakened.
  • go test ./interp ./internal/..., make generate && make check-generated (no diff), make check and git diff --check: pass.
  • The local A/B was on a noisy machine. The CI report decides.

Rejected along the way

Part A, a deferred-release buffer that removed ExitRelease (2557 exits per Run on string-build), removed every release exit but measured string-build +3%. It also delayed host Close side effects, so it was dropped. Exit counts were not the cost.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ef18a5a3-f69b-46c5-9271-801061ecac88
Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

STRING_EQ and STRING_NE lowered natively while STRING_LT, GT, LE and GE
bridged, although all six are one byte-wise content comparison. One
stringCompare now leaves the flags of left against right (the first
differing word, byte-reversed, or byte; else the lengths) and each
relation reads them with its unsigned condition, fused into a branch
when one follows. Equality still leaves early on unequal lengths.

Also state the string units in instruction-set.md (string.len is the
UTF-8 byte length; new/encode_utf32 use code points; ordering is
unsigned byte-wise), and drop a generator branch for a KindAny
CONST_GET that called a removed intern method and never generated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@siyul-park
siyul-park force-pushed the perf/jit-string-compare branch from 21203bd to 0cf7017 Compare November 10, 2026 03:41
@siyul-park
siyul-park merged commit c238efc into main Nov 10, 2026
2 checks passed
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