perf(cli): compile ANSI strip regex once at package scope#3150
Conversation
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
AI Session Analysis
|
| 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
Summary
removeAnsiCharactersFromByteswas recompiling the ANSI escape-code regex on every call. Move the compiled pattern to a package-levelvarso 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.