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

try to reduce the number of allocations #11

Closed
nbari opened this issue Oct 1, 2017 · 1 comment
Closed

try to reduce the number of allocations #11

nbari opened this issue Oct 1, 2017 · 1 comment

Comments

@nbari
Copy link
Owner

nbari commented Oct 1, 2017

When using named params (https://violetear.org/post/context-named/) the router uses 6 allocations, when not it uses 0.

$ make bench
go test -run=^$ -bench=.
2017/10/05 21:57:31 Adding path: /hello [GET,HEAD]
goos: darwin
goarch: amd64
pkg: github.com/nbari/violetear
BenchmarkRouterStatic-4         2017/10/05 21:57:31 Adding path: /hello [GET,HEAD]
2017/10/05 21:57:31 Adding path: /hello [GET,HEAD]
2017/10/05 21:57:31 Adding path: /hello [GET,HEAD]
2017/10/05 21:57:32 Adding path: /hello [GET,HEAD]
10000000               122 ns/op               0 B/op          0 allocs/op
2017/10/05 21:57:33 Adding path: /test/:word [GET,HEAD]
BenchmarkRouterDynamic-4        2017/10/05 21:57:33 Adding path: /test/:word [GET,HEAD]
2017/10/05 21:57:33 Adding path: /test/:word [GET,HEAD]
2017/10/05 21:57:33 Adding path: /test/:word [GET,HEAD]
2017/10/05 21:57:34 Adding path: /test/:word [GET,HEAD]
 2000000               913 ns/op             784 B/op          6 allocs/op
PASS
ok      github.com/nbari/violetear      4.144s

Try to optimize the router to do allocs as little as possible.

@nbari
Copy link
Owner Author

nbari commented Jan 3, 2018

Currently using 0 allocs when using no context, using Name() automatically adds the route name to the context.

A slice could be used to reduce allocations instead of a map but the handlers will depend on GetParam and GetParams

tested but still the same like with the map, closing this for now

@nbari nbari closed this as completed Jan 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant