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

Optimize space for DocumentId with NonZeroUsize #1097

Merged
merged 1 commit into from
Nov 25, 2021

Conversation

pickfire
Copy link
Contributor

@pickfire pickfire commented Nov 14, 2021

Now Option<DocumentId> uses one byte rather than two

Comment on lines 323 to 325
// Safety: adding 1 from 1 is fine, probably impossible to reach usize max
self.next_document_id =
unsafe { NonZeroUsize::new_unchecked(self.next_document_id.get() + 1) };
Copy link
Contributor

Choose a reason for hiding this comment

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

While it "probably" won't happen, it technically could, so I'm not sure we should leave it such that it technically could cause UB.

Copy link
Contributor Author

@pickfire pickfire Nov 14, 2021

Choose a reason for hiding this comment

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

Technically is possible but if the user have that many documents opened, he probably hit an OOM first rather than this. And chances are the files won't hit that, my filesystem only has like 8881511 and 18446744073709551615 is the max, still a long way to go.

And btrfs and ext4 you can't hit that, maybe zfs can since it supports 2^128.

Copy link
Member

@archseer archseer Nov 14, 2021

Choose a reason for hiding this comment

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

We can simplify once nonzero_ops gets stabilized, by using saturating_add.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah

helix-view/src/editor.rs Outdated Show resolved Hide resolved
Now Option<DocumentId> uses one byte rather than two
@archseer archseer merged commit 67bf425 into helix-editor:master Nov 25, 2021
@pickfire pickfire deleted the documentid-size branch November 26, 2021 05:57
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.

3 participants