-
Notifications
You must be signed in to change notification settings - Fork 535
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
Adding new methods to manage the path params map #2645
base: 4.x
Are you sure you want to change the base?
Conversation
fca143e
to
28d5a15
Compare
PTAL @vietj as well |
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.
Thank you Francesco, here are a few comments/concerns.
* Add a new one or replace an existing path parameter | ||
* @throws NullPointerException when the name or value is null | ||
*/ | ||
void addOrReplacePathParam(String name, String value); |
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.
Do we really need this new method? It will create the underlying map if needed anyway.
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.
good point; it was consistent to not expose the underlying form/nature/content of the map - in order to enable to not allocate it, if possible
But any suggestion is more than welcome, bud 🙏 and thanks for looking at this!
boolean removePathParam(String s); | ||
|
||
/** | ||
* Returns an unmodifiable map of named parameters as defined in path declaration with their actual values |
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 is a breaking change that is not mandatory (even if I understand the intention). Can you please revert it?
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.
Do you mean that you prefer to expose it directly as it was? without being not modifiable?
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.
Yes, because we some users will expect this to be modifiable.
if (pathParams == null) { | ||
pathParams = new HashMap<>(); | ||
// let's start small | ||
pathParams = new HashMap<>(1); |
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.
Isn't this too aggressive? How about using 4
, which allows to store 3 path params without rehashing?
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.
in theory with 1 it should have 2 as capacity - but yes, anything but the default can be a good improvement; given that it happen in our hot path, saving half array is still wellcome!
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.
Then, let's be a little conservative and go with 4.
Co-authored-by: Thomas Segismont <[email protected]>
The failure looked unrelated, I've restarted the job |
I've fallen into this while working on improving allocations for Quarkus:
vertx-web/vertx-web/src/main/java/io/vertx/ext/web/impl/RouteState.java
Lines 1225 to 1230 in ed41309
pathParams
, while stillnull
cause allocating itAnd, at the same time, most of the time, the path params are just 1 or 2; meaning that the allocated map doesn't need to have an initial capacity that big.