perf(core-go): zero-allocation memo normalization and routing extraction#276
Merged
Conversation
Resolves Boxkit-Labs#265 Replace regexp.MustCompile and big.Int with allocation-free alternatives on the hot path in the Go routing package: - memo.go: remove digitsOnly regex and uint64Max big.Int package-level vars; add isAllDigits (byte-scan loop) and fitsUint64 (string length + lexicographic compare against uint64MaxStr constant). NormalizeMemoTextID now returns 0 allocs/op on canonical inputs (proved by benchmarks). - extract.go: remove duplicate digitsOnlyRegex var; rewrite normalizeUnsupportedMemoType with strings.Builder to avoid three intermediate string allocations from chained ReplaceAll/ToLower; use pre-computed string literals for known memo-type warning messages; use strings.Builder for the dynamic unrecognized-type message; pre-allocate warning slices with make([]Warning, 0, cap) instead of appending into a zero-capacity slice. - bench_test.go: add 11 benchmarks (BenchmarkNormalizeMemoTextID_*, BenchmarkIsAllDigits, BenchmarkFitsUint64, BenchmarkExtractRouting_*, parallel variants) with b.ReportAllocs(). Results on i7-10510U: NormalizeMemoTextID_Canonical 12.7 ns/op 0 allocs/op NormalizeMemoTextID_MaxUint64 18.3 ns/op 0 allocs/op IsAllDigits 11.3 ns/op 0 allocs/op FitsUint64 0.27 ns/op 0 allocs/op ExtractRouting_GAddr_MemoID 757 ns/op 6 allocs/op (parse-dominated) ExtractRouting_GAddr_Parallel 322 ns/op 6 allocs/op
|
@TheWeirdDee Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
codeZe-us
self-requested a review
June 28, 2026 13:28
codeZe-us
approved these changes
Jun 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #265
Replace regexp.MustCompile and big.Int with allocation-free alternatives on the hot path in the Go routing package:
memo.go: remove digitsOnly regex and uint64Max big.Int package-level vars; add isAllDigits (byte-scan loop) and fitsUint64 (string length + lexicographic compare against uint64MaxStr constant). NormalizeMemoTextID now returns 0 allocs/op on canonical inputs (proved by benchmarks).
extract.go: remove duplicate digitsOnlyRegex var; rewrite normalizeUnsupportedMemoType with strings.Builder to avoid three intermediate string allocations from chained ReplaceAll/ToLower; use pre-computed string literals for known memo-type warning messages; use strings.Builder for the dynamic unrecognized-type message; pre-allocate warning slices with make([]Warning, 0, cap) instead of appending into a zero-capacity slice.
bench_test.go: add 11 benchmarks (BenchmarkNormalizeMemoTextID_, BenchmarkIsAllDigits, BenchmarkFitsUint64, BenchmarkExtractRouting_, parallel variants) with b.ReportAllocs(). Results on i7-10510U:
NormalizeMemoTextID_Canonical 12.7 ns/op 0 allocs/op
NormalizeMemoTextID_MaxUint64 18.3 ns/op 0 allocs/op
IsAllDigits 11.3 ns/op 0 allocs/op
FitsUint64 0.27 ns/op 0 allocs/op
ExtractRouting_GAddr_MemoID 757 ns/op 6 allocs/op (parse-dominated)
ExtractRouting_GAddr_Parallel 322 ns/op 6 allocs/op