bebop / poly

A Go package for engineering organisms.
https://pkg.go.dev/github.com/bebop/poly
MIT License
666 stars 70 forks source link

Precompile most of the regular expressions #274

Closed matiasinsaurralde closed 1 year ago

matiasinsaurralde commented 1 year ago

This PR precompiles most of the regular expressions except for genBankMoleculeTypes and genbankDivisions.

Same approach as #273.

Results in ~10% less allocations and ~10% speed improvement.

benchcmp output:

% benchcmp bench_main.txt bench_new.txt 
benchcmp is deprecated in favor of benchstat: https://pkg.go.dev/golang.org/x/perf/cmd/benchstat
benchmark                old ns/op     new ns/op     delta
BenchmarkRead-8          51142         44201         -13.57%
BenchmarkRead1-8         50456         45411         -10.00%
BenchmarkRead10-8        50317         44153         -12.25%
BenchmarkRead100-8       50074         44064         -12.00%
BenchmarkRead1000-8      49935         44106         -11.67%
BenchmarkRead10000-8     50119         44117         -11.98%

benchmark                old allocs     new allocs     delta
BenchmarkRead-8          697            589            -15.49%
BenchmarkRead1-8         697            589            -15.49%
BenchmarkRead10-8        697            589            -15.49%
BenchmarkRead100-8       697            589            -15.49%
BenchmarkRead1000-8      697            589            -15.49%
BenchmarkRead10000-8     697            589            -15.49%

benchmark                old bytes     new bytes     delta
BenchmarkRead-8          94568         83749         -11.44%
BenchmarkRead1-8         94517         83634         -11.51%
BenchmarkRead10-8        94497         83720         -11.40%
BenchmarkRead100-8       94532         83744         -11.41%
BenchmarkRead1000-8      94605         83778         -11.44%
BenchmarkRead10000-8     94545         83715         -11.45%
gitpod-io[bot] commented 1 year ago

TimothyStiles commented 1 year ago

This is super excellent @matiasinsaurralde! Merged!