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

Improve performance of encoding Uris #660

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

japplis
Copy link
Contributor

@japplis japplis commented Feb 4, 2025

If no encoding occurred for a uri (which is quite often the case), there is no need to convert the StringBuilder to a String, just return the input String.

JMH
Before
Benchmark Mode Cnt Score Error Units
UriParserBenchmark.encode thrpt 25 5814265,085 ▒ 235637,894 ops/s

After
Benchmark Mode Cnt Score Error Units
UriParserBenchmark.encode thrpt 25 6764614,389 ▒ 213170,120 ops/s

16.3% improvement

I've also attached a screenshot of JMC showing that a lot of time of the UriParser.encode is spend in the StringBuilder.toString

profiling-UriParser-encode

Thanks for your contribution to Apache Commons! Your help is appreciated!

Before you push a pull request, review this list:

  • Read the contribution guidelines for this project.
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • [-] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible but is a best-practice.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body. Note that commits might be squashed by a maintainer on merge.

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

Successfully merging this pull request may close these issues.

1 participant