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

Sort the map arguments to optimize insertion performance #185

Merged
merged 1 commit into from
Jun 26, 2023

Conversation

JakeWharton
Copy link
Collaborator

This eliminates internal shifts which occur when the hashcodes of the keys are not ascending.

Closes #4. Manually verified this with debugger. Having #105 would ensure we don't regress.

This eliminates internal shifts which occur when the hashcodes of the keys are not ascending.
@JakeWharton JakeWharton mentioned this pull request Jun 25, 2023
3 tasks
Copy link
Collaborator

@theisenp theisenp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏎️

@JakeWharton JakeWharton merged commit 4284bcb into main Jun 26, 2023
@JakeWharton JakeWharton deleted the jw.sorted.2023-06-24 branch June 26, 2023 22:15
// storage density and minimize runtime complexity, the ideal insertion order sorted, as it
// results in linear insertion into the array with no shifts. Thankfully `String.hashCode()`
// is specified by the documentation and thus safe to rely on across the JVM and Android.
for (argument in arguments.sortedBy { it.key.hashCode() }) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me a few minutes to realize we're sorting at generation-time, not runtime. Cool!

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.

Optimize argument generation
3 participants