Skip to content

perf: apply high-performance-go guidelines across 5 hot paths (3-round review) - #688

Merged
jeduden merged 4 commits into
mainfrom
claude/kind-darwin-v1qz4t
Jun 23, 2026
Merged

perf: apply high-performance-go guidelines across 5 hot paths (3-round review)#688
jeduden merged 4 commits into
mainfrom
claude/kind-darwin-v1qz4t

Conversation

@jeduden

@jeduden jeduden commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

Performance audit against docs/development/high-performance-go.md, fixing 5 violations across core packages. Three rounds of code-review --fix at high severity were applied before merging.

Fixes (commit 7c9dfc7)

Location Violation Fix
internal/export/export.go map[int]bool sets for line tracking map[int]struct{} — zero-size value, same semantics
internal/index/locate.go enclosingListKey FindStringSubmatch(string(lines[i])) — one string() copy per scanned line FindSubmatch(lines[i]) — regex operates directly on []byte
internal/lsp/rename.go / internal/rename/rename.go ValidRefDefBodyLines returned map[int]bool; lookup used map[bool] zero-value Return map[int]struct{}; lookups use _, ok idiom
internal/secreview/render.go locStr fmt.Sprintf(":%d", n) — reflection overhead for integer formatting ":" + strconv.Itoa(n) — ~3× faster, no reflection
internal/rules/concisenessscoring/rule.go message += fmt.Sprintf(...) — intermediate string allocation on verbose path Single fmt.Sprintf via if/else — no extra allocation

Code-review round 1 fixes (commit 917eafa)

  • rule_test.go TestCheck_MessageNoConcatenationWhenExamplesPresent: replaced vacuous assert.NotEmpty with assert.Contains(msg, "e.g.,") — the original guard could never fail
  • locate_test.go: renamed TestEnclosingListKey_NoStringAllocPerLineTestEnclosingListKey_FindsParentKey (old name implied allocation testing the test didn't do)
  • rule_test.go: added TestCheck_NoCuesMessage to cover the examples == "" branch, which was missing coverage (Codecov patch gate was failing at 82%)

Code-review round 2 fixes (commit 12f6a79)

  • locate.go enclosingListKey: removed redundant bytes.TrimSpace(m[2]) — piArgRE's \s*$ suffix structurally guarantees group 2 has no trailing whitespace; replaced with len(m[2]) == 0
  • rule_test.go TestCheck_NoCuesMessage: replaced hardcoded MinScore: 0.50 (fragile against model drift) with a runtime scorer probe — calls NewScorer(), asserts len(Cues) == 0, and sets MinScore = scored.Conciseness + 0.10

Code-review round 3 fixes (commit 3a45453)

  • rule_test.go TestCheck_MessageNoConcatenationWhenExamplesPresent: removed conditional guard if strings.Contains(msg, "reduce verbose cues") — the inner assert.Contains(msg, "e.g.,") was dead code in the exact regression it was meant to catch (if implementation drops cue text, the outer if is false and the inner assert never runs); verboseParagraph() always produces cues so both asserts are now unconditional
  • rule.go: unified the two fmt.Sprintf call sites (sharing the same base format and three repeated arguments) into a single call with a conditional cuesSuffix string — base format string now lives in one place

Test plan

  • All tests pass: go test ./...
  • Codecov patch coverage ≥ 98.62% (green on all 4 commits)
  • Three rounds of code-review --fix at high severity — no surviving CONFIRMED findings after round 3
  • go vet ./... clean

🤖 Generated with Claude Code

https://claude.ai/code/session_015QYub2iGP6CeeEFSfjV3Wv

Audited the codebase against docs/development/high-performance-go.md
and fixed the five highest-impact violations identified by scanning
internal/ and rules/.

1. rename: map[int]bool → map[int]struct{} (guideline: map[K]struct{}
   for sets). ValidRefDefBodyLines and contentBlockLines tracked
   presence-only with bool values; struct{} removes the 1-byte value
   overhead and makes the set semantics explicit. Updated callers in
   lsp/rename.go and rename_test.go.

2. export: map[int]bool → map[int]struct{} for stripLines/bodyLines
   (same guideline). stripDirectives, overlapsAny, and emitLines all
   operated on presence-only maps; changed all three sites.

3. secreview/render: fmt.Sprintf(":%d") → strconv.Itoa (guideline:
   strconv over fmt.Sprintf). strconv.Itoa is ~3× faster than
   fmt.Sprintf for integer formatting because it skips reflection and
   format-string parsing.

4. index/locate: eliminate string(lines[i]) per loop iteration in
   enclosingListKey (guideline: stay in []byte). FindSubmatch([]byte)
   replaces FindStringSubmatch(string(line)), removing one heap
   allocation per scanned line in the upward-scan loop. Only the
   matched key group is converted to string at the return point.

5. concisenessscoring: eliminate message += fmt.Sprintf pattern
   (guideline: strings.Builder over +). A single conditional
   fmt.Sprintf replaces the initial Sprintf followed by a
   string-concatenation assignment, removing one heap allocation per
   diagnostic when verbose cues are present.

All tests pass. mdsmith check . reports 0 failures.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015QYub2iGP6CeeEFSfjV3Wv
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.62%. Comparing base (1599c9f) to head (3a45453).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files
Components Coverage Δ
Go 98.61% <100.00%> (-0.01%) ⬇️
TypeScript 99.54% <ø> (ø)

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

claude added 3 commits June 23, 2026 20:36
…rage

Three test improvements from code-review round 1:

- rule_test.go: replace vacuous assert.NotEmpty (which strings.Contains
  already implies non-empty) with a meaningful assert.Contains for "e.g.,"
  so the assertion can actually go red if the format string loses its
  example section

- rule_test.go: add TestCheck_NoCuesMessage to exercise the
  `if examples == ""` branch — verboseParagraph always produces cues so
  the base-message-only path was uncovered; fixes the Codecov patch check
  failure (40% → 100% on that branch)

- locate_test.go: rename TestEnclosingListKey_NoStringAllocPerLine to
  TestEnclosingListKey_FindsParentKey; the test only asserts the return
  value, not allocation behaviour, so the old name was misleading

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015QYub2iGP6CeeEFSfjV3Wv
Two follow-on fixes from code review round 2:

- locate.go: piArgRE's `\s*$` suffix already strips trailing
  whitespace from capture group 2, so `bytes.TrimSpace(m[2])` was
  always a no-op; replace with plain `len(m[2]) == 0`.

- concisenessscoring/rule_test.go: TestCheck_NoCuesMessage previously
  used a hardcoded MinScore of 0.50, which would break if the
  embedded model drifts.  Rewrite to probe NewScorer() at runtime,
  assert len(Cues)==0 (skip if the model now sees cues), and set
  MinScore = scored.Conciseness + 0.10 so the threshold is always
  just above the actual score.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015QYub2iGP6CeeEFSfjV3Wv
…seness rule

Two fixes from code-review round 3:

- rule_test.go: TestCheck_MessageNoConcatenationWhenExamplesPresent guarded
  the assert.Contains(msg, "e.g.,") behind `if strings.Contains(msg, "reduce
  verbose cues")`, making it a no-op in the exact regression it was meant to
  catch (message drops cue text → outer if is false → inner assert never runs).
  verboseParagraph() always produces cues, so assert both strings
  unconditionally. Remove the now-unused "strings" import.

- rule.go: Replace the if/else with two identical fmt.Sprintf call sites (same
  three arguments, same format prefix) with a single call that takes a
  conditional cuesSuffix string. The base format string now lives in one place
  so it can't diverge between the cue and no-cue paths.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015QYub2iGP6CeeEFSfjV3Wv
@jeduden jeduden changed the title perf: apply high-performance-go guidelines across 5 hot paths perf: apply high-performance-go guidelines across 5 hot paths (3-round review) Jun 23, 2026
@jeduden
jeduden marked this pull request as ready for review June 23, 2026 20:54
@jeduden jeduden added queue Add to a PR to enqueue it queue:active Applied automatically when a PR is in an active batch and removed queue Add to a PR to enqueue it labels Jun 23, 2026
@jeduden

jeduden commented Jun 23, 2026

Copy link
Copy Markdown
Owner Author

🟢 Merge Queue — picked up

This PR is in the queue and will be batched with other queue-labelled PRs.

Next: No action needed — you'll get another comment when CI starts on the batch. View merge queue run.

@jeduden

jeduden commented Jun 23, 2026

Copy link
Copy Markdown
Owner Author

🔵 Merge Queue — CI running

Merged into batch branch merge-queue/batch-688-1782251381. View CI run.

Next: No action needed — you'll be notified when CI completes.

@jeduden jeduden removed the queue:active Applied automatically when a PR is in an active batch label Jun 23, 2026
@jeduden
jeduden merged commit 09f22d3 into main Jun 23, 2026
31 checks passed
@jeduden

jeduden commented Jun 23, 2026

Copy link
Copy Markdown
Owner Author

Merge Queue — merged

This PR landed on main via commit 09f22d3. CI run that validated the merge.

Next: Done — nothing more to do here.

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