moov-io / ach

ACH implements a reader, writer, and validator for Automated Clearing House (ACH) files. The HTTP server is available in a Docker image and the Go package is available.
https://moov-io.github.io/ach/
Apache License 2.0
452 stars 150 forks source link

perf: reduce allocations in some formatting and validation functions #1307

Closed adamdecaf closed 10 months ago

adamdecaf commented 10 months ago

Two nice performance / memory improvements.

numericField ``` goos: darwin goarch: amd64 pkg: github.com/moov-io/ach cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz BenchmarkNumericFieldShort BenchmarkNumericFieldShort-16 97991214 118.7 ns/op 24 B/op 3 allocs/op BenchmarkNumericFieldLong BenchmarkNumericFieldLong-16 338344930 36.13 ns/op 8 B/op 1 allocs/op PASS ok github.com/moov-io/ach 28.253s ``` ``` goos: darwin goarch: amd64 pkg: github.com/moov-io/ach cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz BenchmarkNumericFieldShort BenchmarkNumericFieldShort-16 186805923 64.67 ns/op 16 B/op 2 allocs/op BenchmarkNumericFieldLong BenchmarkNumericFieldLong-16 398885554 30.35 ns/op 8 B/op 1 allocs/op PASS ok github.com/moov-io/ach 34.381s ```
CalculateCheckDigit ``` goos: darwin goarch: amd64 pkg: github.com/moov-io/ach cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz BenchmarkCalculateCheckDigit BenchmarkCalculateCheckDigit/valid BenchmarkCalculateCheckDigit/valid-16 85632897 139.3 ns/op 32 B/op 8 allocs/op PASS ok github.com/moov-io/ach 12.267s ``` ``` goos: darwin goarch: amd64 pkg: github.com/moov-io/ach cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz BenchmarkCalculateCheckDigit BenchmarkCalculateCheckDigit/valid BenchmarkCalculateCheckDigit/valid-16 437170713 27.36 ns/op 0 B/op 0 allocs/op PASS ok github.com/moov-io/ach 15.385s ```