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

Faster deref of inline atoms #277

Merged
merged 1 commit into from
Jul 17, 2024
Merged

Conversation

overlookmotel
Copy link
Contributor

@overlookmotel overlookmotel commented Jul 4, 2023

Deref of an atom (e.g. atom.to_string()) which stores the string inline performs slicing with &src[..len]. len is guaranteed to be within bounds, as an inline atom is always 7 bytes or less, so this can be substituted with src.get_unchecked(..len).

Removing this bounds check improves performance of deref-ing an inline atom by approx 30%.

There's a lot of noise in the benchmarks, but it also seems to slightly improve performance of deref-ing static and dynamic atoms too, presumably because it reduces the size of the deref() function.

NB There's no gain to making the same change in From<Cow<'a, str>> for Atom<Static> because the compiler already deduces no bounds check is required due to the if len <= MAX_INLINE_LEN conditional.

@overlookmotel
Copy link
Contributor Author

@nicoburns Thanks for reviewing. Are you a maintainer of this project and able to merge?

@nicoburns
Copy link

nicoburns commented Jul 17, 2024

@nicoburns Thanks for reviewing. Are you a maintainer of this project and able to merge?

I am, but I'm new to working with this crate, so I'm going to seek feedback before I go ahead and merge. I will look to push this forwards though :) See: https://servo.zulipchat.com/#narrow/stream/263398-general/topic/The.20.60string_cache.60.20crate

@overlookmotel
Copy link
Contributor Author

@nicoburns Amazing! Would be really great if this crate received some attention, and really appreciate it that you're willing to do so.

@nicoburns nicoburns added this pull request to the merge queue Jul 17, 2024
Merged via the queue into servo:main with commit 1b636e9 Jul 17, 2024
5 checks passed
@overlookmotel
Copy link
Contributor Author

Thanks very much for merging!

@overlookmotel overlookmotel deleted the faster-inline branch July 17, 2024 22:21
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.

2 participants