Skip to content

Comments

perf: speed up toCSVSummary#648

Merged
boyter merged 1 commit intoboyter:masterfrom
apocelipes:optimize-csv
Sep 30, 2025
Merged

perf: speed up toCSVSummary#648
boyter merged 1 commit intoboyter:masterfrom
apocelipes:optimize-csv

Conversation

@apocelipes
Copy link
Contributor

Optimizations:

  • Sorting summaries is faster than sorting string arrays, so sorting summaries before serializing.
  • Reusing memory reduces the performance overhead when serializing to CSV.

These optimizations can gain performance improvements:

goos: darwin
goarch: arm64
pkg: github.com/boyter/scc/v3/processor
cpu: Apple M4
                 │     old     │                 new                 │
                 │   sec/op    │   sec/op     vs base                │
FileSummerize-10   1.696µ ± 1%   1.467µ ± 6%  -13.51% (p=0.000 n=10)

                 │     old      │                 new                  │
                 │     B/op     │     B/op      vs base                │
FileSummerize-10   5.375Ki ± 0%   4.828Ki ± 0%  -10.17% (p=0.000 n=10)

                 │     old     │                new                 │
                 │  allocs/op  │ allocs/op   vs base                │
FileSummerize-10   12.000 ± 0%   7.000 ± 0%  -41.67% (p=0.000 n=10)

This is the case where only two languages are involved. The more languages included in the result, the larger the improvement achieved.

Optimizations:
- Sorting summaries is faster than sorting string arrays, so sorting summaries before serializing.
- Reusing memory reduces the performance overhead when serializing to CSV.

These optimizations can gain performance improvements:

goos: darwin
goarch: arm64
pkg: github.com/boyter/scc/v3/processor
cpu: Apple M4
                 │     old     │                 new                 │
                 │   sec/op    │   sec/op     vs base                │
FileSummerize-10   1.696µ ± 1%   1.467µ ± 6%  -13.51% (p=0.000 n=10)

                 │     old      │                 new                  │
                 │     B/op     │     B/op      vs base                │
FileSummerize-10   5.375Ki ± 0%   4.828Ki ± 0%  -10.17% (p=0.000 n=10)

                 │     old     │                new                 │
                 │  allocs/op  │ allocs/op   vs base                │
FileSummerize-10   12.000 ± 0%   7.000 ± 0%  -41.67% (p=0.000 n=10)
@pr-insights pr-insights bot added VH/complexity Very high complexity XL/size Extra large change labels Sep 29, 2025
@boyter boyter merged commit 148761b into boyter:master Sep 30, 2025
4 checks passed
@boyter
Copy link
Owner

boyter commented Sep 30, 2025

Thank you.

@apocelipes apocelipes deleted the optimize-csv branch October 1, 2025 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

VH/complexity Very high complexity XL/size Extra large change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants