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

internal/methods: add benchmarks #1

Closed
dolmen opened this issue Jul 1, 2024 · 5 comments
Closed

internal/methods: add benchmarks #1

dolmen opened this issue Jul 1, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@dolmen
Copy link

dolmen commented Jul 1, 2024

Functions in package internal/methods could be faster. But let's start by measuring performance: add benchmarks.

@jub0bs
Copy link
Owner

jub0bs commented Jul 2, 2024

Hello @dolmen! Thanks for filing this issue.

I must admit I haven't focused too much on the performance of those functions, since they're only invoked during middleware instantiation and not on the hot path (middleware invocation).

Which of those methods do you think could be faster?

I'd be happy to add some benchmarks around them, but I'd like to know more about what you have in mind first.

@dolmen
Copy link
Author

dolmen commented Jul 2, 2024

A benchmark is definitely irrelevant if those functions are not used beyond the middleware instantiation.

My concerns were about the use of a map (via util.Set) just to check for the presence of a value in a set of 3 elements: using a slice and slices.Contains would simplify the implementation, and, I expect, be faster.

@dolmen
Copy link
Author

dolmen commented Jul 2, 2024

I'm now more concerned about the use of util.Set for Config.allowedMethods.

@jub0bs
Copy link
Owner

jub0bs commented Jul 2, 2024

My concerns were about the use of a map (via util.Set) just to check for the presence of a value in a set of 3 elements [...]

Fair enough. A util.Set might be overkill. I'll write a benchmark to compare the performance with that of a linear search or binary search through a []string.

I'm now more concerned about the use of util.Set for Config.allowedMethods.

This is more delicate. The cardinality of Config.allowedMethods is unbounded; storing the allowed methods in a slice could be detrimental to performance.

@jub0bs jub0bs added the enhancement New feature or request label Jul 2, 2024
@jub0bs
Copy link
Owner

jub0bs commented Jul 5, 2024

After thinking a bit more about this, I'm still not convinced a change in this area of the code is worth it. I'm going to close this issue for now, but I'm happy to hear counterarguments.

@jub0bs jub0bs closed this as completed Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants