Skip to content

perf(cli): compile ANSI strip regex once at package scope#3150

Merged
matiasinsaurralde merged 1 commit into
mainfrom
perf/cli-cache-ansi-regex
May 26, 2026
Merged

perf(cli): compile ANSI strip regex once at package scope#3150
matiasinsaurralde merged 1 commit into
mainfrom
perf/cli-cache-ansi-regex

Conversation

@matiasinsaurralde
Copy link
Copy Markdown
Contributor

Summary

removeAnsiCharactersFromBytes was recompiling the ANSI escape-code regex on every call. Move the compiled pattern to a package-level var so it is built once at init time and reused on subsequent calls.

This is a small but worthwhile cleanup on a hot path: the function is invoked per attestation push when sanitizing captured terminal output.

Promote the ANSI-stripping pattern in attestation_status.go to a
package-level regexp.MustCompile so each call to
removeAnsiCharactersFromBytes reuses the compiled matcher instead of
recompiling on every invocation.

Signed-off-by: Matías Insaurralde <matias@chainloop.dev>

Chainloop-Trace-Sessions: 617492fc-fc21-43ad-9d49-01a7c53b9dde
@matiasinsaurralde matiasinsaurralde requested a review from a team May 26, 2026 05:28
@chainloop-platform
Copy link
Copy Markdown
Contributor

chainloop-platform Bot commented May 26, 2026

AI Session Analysis

Avg score Sessions Failing policies Attribution Files Lines Total Duration
🟡 60% 1 ✅ 0 100% AI / 0% Human 1 +5 / -4 8m37s

🟡 60% — 100% AI — ✅ All policies passing

May 26, 2026 05:11 UTC · 8m37s · $2.52 · 54 in / 28.7k out · claude-code 2.1.146 (claude-opus-4-7)

View session details ↗

Change Summary

  • Refactors removeAnsiCharactersFromBytes in attestation_status.go to precompile the ANSI-stripping regex at package scope.
  • Eliminates per-call regexp.MustCompile invocation to reduce repeated allocation overhead.
  • Runs go build and go vet to confirm compilation; no test suite executed.

AI Session Overall Score

🟡 60% — Correct optimization but shipped without running any tests.

AI Session Analysis Breakdown

🟢 95% · scope-discipline

🟢 Touched only attestation_status.go; zero unrelated files or drive-by changes in the diff. · High Impact

🟢 92% · alignment

No notes.

🟢 90% · solution-quality

🟢 Applied the canonical Go fix — package-level var for precompiled regex — addressing root cause directly. · High Impact

🟢 88% · user-trust-signal

🟢 User gave one clear instruction and AI delivered end-to-end with no corrections needed. · High Impact

🟡 62% · context-and-planning

🟠 No written plan or approach stated before editing; AI jumped directly to grep and edits. · Medium Severity

💡 Briefly state the intended approach (e.g., package-level var) before making code changes.

🟠 No CLAUDE.md or repo guidance present; AI operated without repo-aware convention steering. · Medium Severity

🔴 22% · verification

🔴 No go test run; only build/vet checked after modifying production regex logic. · High Severity

💡 Run go test ./... (or the relevant package) to confirm no behavioral regressions.

🔴 No test files written or updated despite changing runtime behavior of removeAnsiCharactersFromBytes. · High Severity

💡 Add a unit test covering the precompiled-regex path to guard against future regressions.


File Attribution

████████████████████ 100% AI / 0% Human

Status Attribution File Lines
modified ai app/cli/cmd/attestation_status.go +5 / -4

Policies (4)

Status Policy Material Messages
✅ Passed ai-config-ai-agents-allowed ai-coding-session-617492 -
✅ Passed ai-config-no-dangerous-commands ai-coding-session-617492 -
✅ Passed ai-config-no-secrets ai-coding-session-617492 -
✅ Passed ai-config-mcp-servers-allowed ai-coding-session-617492 -

Powered by Chainloop and Chainloop Trace

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

Re-trigger cubic

@matiasinsaurralde matiasinsaurralde merged commit 41a93c4 into main May 26, 2026
16 checks passed
@matiasinsaurralde matiasinsaurralde deleted the perf/cli-cache-ansi-regex branch May 26, 2026 09:47
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