introduce a new method (set_host_to_base_host) to replace set_host when set_host is unnecessary #762
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In our main parsing function, we repeatedly call set_host. This is a relatively expensive setter function.
It is only a wrapper around
set_host_or_hostname<false>
, but that function is not cheap...Let us look at it:
This function in turn will call
parse_host
.We are replacing all of that by
This tiny function is obviously cheaper. :-)
Its most expensive call is
update_base_hostname
, which is quite cheap:So let us look at a little benchmark.... This will not affect cases where we are parsing a single URL. It is only relevant when we have a base URL. We have one benchmark for this (
wpt_bench
).Apple system:
Before:
After:
Linux system:
Before:
After:
Conclusion
This seems like a clear (if small) win when parsing URLs with a base.