ROX-35259: reduce formatProcess allocs in risk scoring#21353
Conversation
Pre-size strings.Builder and replace stringutils.WriteStringf (which uses fmt.Sprintf + %%q) with direct WriteString + strconv.Quote. Eliminates ~171M heap allocations per reprocessing cycle from fmt machinery and builder growth.
|
Skipping CI for Draft Pull Request. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Enterprise Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
🚀 Build Images ReadyImages are ready for commit ac32438. To use with deploy scripts: export MAIN_IMAGE_TAG=4.12.x-269-gac32438390 |
| sb := strings.Builder{} | ||
| stringutils.WriteStringf(&sb, "Detected execution of suspicious process %q", process.SignalName) | ||
| sb.Grow(128) |
There was a problem hiding this comment.
Why 128? The strings are likely to be longer with signalname and signalargs
Description
Stacked on #21352.
formatProcessusesstringutils.WriteStringf(which callsfmt.Sprintfinternally)with the
%qverb for every violating process indicator. The fmt machinery, quoted-stringformatting, and
strings.Buildergrowth account for ~171M heap allocations perreprocessing cycle in production profiles.
Fix: pre-size the
strings.Builderto 128 bytes and usestrconv.Quote+direct
WriteStringcalls instead of the fmt-based path. Output is identical(
%qandstrconv.Quoteproduce the same Go-quoted string).User-facing documentation
Testing and quality
Automated testing
How I validated my change
central/risk/multipliers/deploymentpassstrconv.Quoteproduces identical output to%q— both use Go quoted-string formatalloc_objectsprofile of Central under steady-state load (1.35h capture)🤖 Generated with Claude Code