-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fixes #2016 - make IP() and IPs() more reliable #2020
Conversation
Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
ctx.go
Outdated
// extractValidIPs will return a slice of strings that represent valid IP addresses | ||
// in the input string. The order is maintained. The separator is a comma | ||
func extractValidIPs(input string) (validIPs []string) { | ||
unvalidatedIps := strings.Split(input, ",") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this leads to further allocations
what does the benchmark say about the adjustment ?
please try to minimize the allocations so that we keep our perfomance promise for the consumers
@gbolo can you try to make it more allocation less ? to improve the performance |
@ReneWerner87 I can try. Do you have any suggestions on an approach? Previously for the length of the ips slice, it was easy to figure out because you simply just counted the numbers of commas + 1:
However, it's a little trickier now because we need to validate the input first. I will try another approach and run benchmarks to measure the impact. |
Lines 173 to 180 in 1fec875
without storing the ip in a separate slice |
I have improved the performance and reduced allocations of this functionality. I will continue to improve it more this week. I was also thinking that it may be a good idea to allow IP validation to be a configuration option. What do you think @ReneWerner87 ? Current performance:
Previous performance with high allocations:
Existing performance with NO ip validation
|
thank you, would say ip validation is not needed for now |
are you finished or do you want to make adjustments ? otherwise i would merge |
please don't merge yet, I want to make some more adjustments |
@ReneWerner87 I have completed the feature now. The performance of validation is improved, and also it is now an optional configuration flag. It is disabled by default to maintain identical performance and functionality as the previous releases. I also added many new unit tests and benchmark tests to track the feature.
to enable this feature simply enable it with config:
Thanks for your help in reviewing this feature @ReneWerner87 |
For new features don't forget to create a doc entry in our documentation repository. |
done: gofiber/docs#272 |
Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
see #2016