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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

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.

None yet

1 participant