howeyc / ledger

Command line double-entry accounting program
https://howeyc.github.io/ledger/
ISC License
455 stars 43 forks source link

Streamline synchronous processing #19

Closed bionoren closed 5 years ago

bionoren commented 5 years ago

Moved ledger parsing logic into a helper function using a callback model similar to filepath.Walk so that ledger.ParseLedger doesn't have to incur memory and context switching overhead of channels and goroutines.

This change results in a 10x performance improvement and a significant reduction in allocations for the existing benchmark.

Before: BenchmarkParseLedger-8 300000 3380 ns/op 4336 B/op 6 allocs/op

After: BenchmarkParseLedger-8 3000000 528 ns/op 4096 B/op 1 allocs/op

Resolves issue #18