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

perf: improve try_files matcher #6709

Closed

Conversation

dunglas
Copy link
Collaborator

@dunglas dunglas commented Nov 24, 2024

This is an experiment to use repl.Match() to (likely) prevent useless string manipulations.
This improve the performance of 2%, but consumes 10% more memory. I'm not sure if it is worth it. (the gain is likely a better on Windows)

Before:

goos: darwin
goarch: arm64
pkg: github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver
cpu: Apple M1 Pro
BenchmarkFileMatcher
BenchmarkFileMatcher-10    	   81501	     14692 ns/op	     920 B/op	      22 allocs/op
PASS

After:

goos: darwin
goarch: arm64
pkg: github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver
cpu: Apple M1 Pro
BenchmarkFileMatcher
BenchmarkFileMatcher-10    	   81658	     14410 ns/op	    1022 B/op	      20 allocs/op
PASS

@dunglas dunglas marked this pull request as draft November 24, 2024 22:16
@dunglas
Copy link
Collaborator Author

dunglas commented Nov 25, 2024

Likey useless.

@dunglas dunglas closed this Nov 25, 2024
@mholt
Copy link
Member

mholt commented Nov 25, 2024

This is kinda surprising to me, as it should only make allocations if invoked.

Maybe the benchmark is not representative of real life use?

@mholt
Copy link
Member

mholt commented Nov 25, 2024

Hmm no the benchmark looks fine 🤔

@dunglas
Copy link
Collaborator Author

dunglas commented Nov 25, 2024

Map() itself needs to allocate to keep the data available until it is called.

Here it is not worth it at least on Unix because ToSlash() basically does nothing on this OS.

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