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

Optimize memory allocations on building patterns with strings.Builder #47

Merged
merged 5 commits into from
Sep 1, 2024

Conversation

rhysd
Copy link
Contributor

@rhysd rhysd commented Sep 1, 2024

This PR contains the following improvements

  • Optimize building patterns with strings.Builder (the primary change)
    • strings.Builder was added at Go 1.10 (the version in go.mod is 1.12)
  • Add BenchmarkGlob to measure performance
  • Small fixes to make staticcheck happy
  • Fix a badge in readme

The performance gain by this PR is as follows:

Before:

$ go test -bench . -benchmem
goos: darwin
goarch: amd64
pkg: github.com/mattn/go-zglob
cpu: Intel(R) Core(TM) i9-10910 CPU @ 3.60GHz
BenchmarkGlob-20             236           5027318 ns/op          249671 B/op       4139 allocs/op
PASS
ok      github.com/mattn/go-zglob       2.004s

After:

$ go test -bench . -benchmem
goos: darwin
goarch: amd64
pkg: github.com/mattn/go-zglob
cpu: Intel(R) Core(TM) i9-10910 CPU @ 3.60GHz
BenchmarkGlob-20             238           5011009 ns/op          249391 B/op       3706 allocs/op
PASS
ok      github.com/mattn/go-zglob       1.823s

Summary:

  • Allocations: 11.68% smaller
  • CPU: 0.325% faster (identical)

@mattn mattn merged commit df0b60a into mattn:master Sep 1, 2024
1 check passed
@mattn
Copy link
Owner

mattn commented Sep 1, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants