Skip to content

Stream rewritten SPDX identifiers - #28

Merged
andrew merged 1 commit into
mainfrom
perf/rewrite-identifiers-stream
Sep 6, 2026
Merged

Stream rewritten SPDX identifiers#28
andrew merged 1 commit into
mainfrom
perf/rewrite-identifiers-stream

Conversation

@andrew

@andrew andrew commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

RewriteIdentifiers currently builds a second expression tree and then renders it. This change writes rewritten identifiers directly to a strings.Builder while preserving callback order, precedence, license references, exceptions, special values, and input immutability.

For an expression with 128 identifiers, the local benchmark falls from about 20.5 microseconds and 71.6 KB allocated to 4.7 microseconds and 3.0 KB. A differential fuzzer compares the streaming result with the former clone-based implementation across valid syntax trees.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The streaming implementation matches existing String() precedence/parenthesization rules (including WITH wrapping under OR), preserves callback order, and is backed by differential fuzzing plus existing rewrite-order tests.

Pull request overview

This pull request optimizes RewriteIdentifiers by streaming rewritten SPDX expression output directly into a strings.Builder instead of cloning and re-rendering a second expression tree, while preserving the existing normalization/precedence rules and rewrite callback order.

Changes:

  • Replace clone-based rewriting with a streaming writeRewritten(*strings.Builder, rewrite, parentToken) implementation across expression node types.
  • Add a fuzz test to differential-check streaming output vs a clone-based reference implementation, plus a size-scaled benchmark.
  • Update the Expression interface to support streaming rewriting.
File summaries
File Description
rewrite.go Implements streaming rewrite via writeRewritten methods and a small fast-path in RewriteIdentifiers.
rewrite_stream_test.go Adds differential fuzzing against a clone-based implementation and benchmarks across expression sizes.
parse.go Updates Expression interface to include writeRewritten, enabling streaming rewriting across node types.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@andrew
andrew merged commit fa05967 into main Sep 6, 2026
6 checks passed
@andrew
andrew deleted the perf/rewrite-identifiers-stream branch September 6, 2026 21: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.

2 participants