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

text: Wrap BufferId in a newtype #6993

Merged
merged 2 commits into from
Jan 29, 2024
Merged

text: Wrap BufferId in a newtype #6993

merged 2 commits into from
Jan 29, 2024

Conversation

osiewicz
Copy link
Contributor

@osiewicz osiewicz commented Jan 29, 2024

This change is two-fold:

  1. We want to use more newtypes, and buffer ID's have been represented as u64's all over the place. It feels like a pretty fundamental identifier.
  2. I want to switch the internal type of buffer id to NonZeroU64 to make use of niche optimization (as it should reduce text::Anchor size by 20%).

TODO:

  • ensure that prod can make use of this change (as is, I'm not sure if JoinChannelResponse.buffer_id can ever be 0).

Dev tl;dr: decreases size of text::Anchor from 40 to 32 bytes by making Option<BufferId> take up 8 bytes instead of 16.

Release Notes:

  • N/A

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 29, 2024
@osiewicz osiewicz marked this pull request as ready for review January 29, 2024 16:05
@osiewicz
Copy link
Contributor Author

osiewicz commented Jan 29, 2024

Both SERIAL in PostgreSQL and AUTOINCREMENT in SQLite start off at 1, so we should be safe here. We've checked prod db with @maxbrunsfeld and we don't have a channel buffer with id=0 (that aligns with ids starting off at 1), so this PR should be good to go.

@osiewicz osiewicz merged commit b29f45e into main Jan 29, 2024
10 checks passed
@osiewicz osiewicz deleted the newtype_bufferid branch January 29, 2024 19:00
@ConradIrwin
Copy link
Member

@osiewicz / @maxbrunsfeld This breaks collaboration between versions of zed before and after the change because older clients do in fact send a buffer id of zero (I think if they're sharing the first opened in a workspace), which causes newer clients to hit an assertion in the workspace and panic.

I'm going to assume we're ok for following between stable and preview to be broken for one file per workspace for one week; leave this in place, and fix the assertion to log an error instead.

ConradIrwin added a commit that referenced this pull request Jan 31, 2024
Older Zed versions may send a buffer id of 0, which is no-longer
supported. (as of #6993)

This doesn't fix that, but it does ensure that we don't panic in the
workspace by maintaining the invariant that from_proto_state returns
Some(Task) if the variant matches.

It also converts the panic to an error should something similar happen
again in the future.


Release Notes:

- N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants