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

Adding new methods to manage the path params map #2645

Open
wants to merge 2 commits into
base: 4.x
Choose a base branch
from

Conversation

franz1981
Copy link

I've fallen into this while working on improving allocations for Quarkus:

  • quarkus register several routes
  • some of these routes, while iterated to find a match, hit
    if (exactPath) {
    // exact path has no "rest"
    ctx.pathParams()
    .remove("*");
    return pathMatchesExact(thePath, requestPath, pathEndsWithSlash);
  • calling pathParams, while still null cause allocating it

And, 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.

@franz1981 franz1981 changed the title 4.x path params Adding new methods to manage the path params map Sep 5, 2024
@franz1981
Copy link
Author

PTAL @vietj as well

Copy link
Contributor

@tsegismont tsegismont left a 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);
Copy link
Contributor

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.

Copy link
Author

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
Copy link
Contributor

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?

Copy link
Author

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?

Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Author

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!

Copy link
Contributor

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.

@tsegismont
Copy link
Contributor

The failure looked unrelated, I've restarted the job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants