Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseModel() performance improvements #14

Merged
merged 2 commits into from
Aug 1, 2024
Merged

parseModel() performance improvements #14

merged 2 commits into from
Aug 1, 2024

Conversation

marselester
Copy link
Contributor

Quick perf wins in parseModel(): 29.79% less allocs, 6.28% less memory used, 1.41% speed up in runtime.

$ benchstat old.txt new.txt                        
goos: darwin
goarch: arm64
pkg: github.com/maxmind/xgbshap
              │   old.txt   │              new.txt               │
              │   sec/op    │   sec/op     vs base               │
ParseModel-10   684.4µ ± 1%   674.7µ ± 2%  -1.41% (p=0.011 n=10)

              │   old.txt    │               new.txt               │
              │     B/op     │     B/op      vs base               │
ParseModel-10   186.6Ki ± 0%   174.9Ki ± 0%  -6.28% (p=0.000 n=10)

              │   old.txt   │               new.txt               │
              │  allocs/op  │  allocs/op   vs base                │
ParseModel-10   1.588k ± 0%   1.115k ± 0%  -29.79% (p=0.000 n=10)
before
$ go test -run=^$ -bench=. -benchmem -count=10 | tee old.txt
goos: darwin
goarch: arm64
pkg: github.com/maxmind/xgbshap
BenchmarkParseModel-10    	    1752	    683160 ns/op	  191080 B/op	    1588 allocs/op
BenchmarkParseModel-10    	    1737	    683685 ns/op	  191080 B/op	    1588 allocs/op
BenchmarkParseModel-10    	    1744	    685918 ns/op	  191080 B/op	    1588 allocs/op
BenchmarkParseModel-10    	    1744	    684606 ns/op	  191081 B/op	    1588 allocs/op
BenchmarkParseModel-10    	    1748	    683018 ns/op	  191080 B/op	    1588 allocs/op
BenchmarkParseModel-10    	    1747	    684094 ns/op	  191080 B/op	    1588 allocs/op
BenchmarkParseModel-10    	    1746	    688603 ns/op	  191080 B/op	    1588 allocs/op
BenchmarkParseModel-10    	    1759	    799020 ns/op	  191080 B/op	    1588 allocs/op
BenchmarkParseModel-10    	    1736	    682506 ns/op	  191080 B/op	    1588 allocs/op
BenchmarkParseModel-10    	    1748	    686241 ns/op	  191080 B/op	    1588 allocs/op
PASS
ok  	github.com/maxmind/xgbshap	15.022s
after
$ go test -run=^$ -bench=. -benchmem -count=10 | tee new.txt
goos: darwin
goarch: arm64
pkg: github.com/maxmind/xgbshap
BenchmarkParseModel-10    	    1776	    676684 ns/op	  179090 B/op	    1115 allocs/op
BenchmarkParseModel-10    	    1773	    672871 ns/op	  179088 B/op	    1115 allocs/op
BenchmarkParseModel-10    	    1774	    674630 ns/op	  179088 B/op	    1115 allocs/op
BenchmarkParseModel-10    	    1774	    675294 ns/op	  179089 B/op	    1115 allocs/op
BenchmarkParseModel-10    	    1767	    674292 ns/op	  179089 B/op	    1115 allocs/op
BenchmarkParseModel-10    	    1767	    672589 ns/op	  179088 B/op	    1115 allocs/op
BenchmarkParseModel-10    	    1772	    674810 ns/op	  179088 B/op	    1115 allocs/op
BenchmarkParseModel-10    	    1770	    777569 ns/op	  179088 B/op	    1115 allocs/op
BenchmarkParseModel-10    	    1776	    672042 ns/op	  179088 B/op	    1115 allocs/op
BenchmarkParseModel-10    	    1770	    687123 ns/op	  179088 B/op	    1115 allocs/op
PASS
ok  	github.com/maxmind/xgbshap	13.984s

Copy link

Modver result

This report was generated by Modver,
a Go package and command that helps you obey semantic versioning rules in your Go module.

This PR requires an increase in your module’s major version number.
If the new major version number is 2 or greater,
you must also add or update the version suffix
on the module path defined in your go.mod file.
See the Go Modules Reference for more info.

checking Tree
  struct field Nodes changed in github.com/maxmind/xgbshap.Tree
    *github.com/maxmind/xgbshap.Node went from pointer to non-pointer
      Major

@horgh horgh merged commit ed3a1c8 into main Aug 1, 2024
17 checks passed
@horgh horgh deleted the parse-model-perf branch August 1, 2024 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants