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

Consider switching Taffy API to use interior mutability #816

Open
nicoburns opened this issue Mar 18, 2025 · 0 comments
Open

Consider switching Taffy API to use interior mutability #816

nicoburns opened this issue Mar 18, 2025 · 0 comments
Labels
usability Make the library more comfortable to use

Comments

@nicoburns
Copy link
Collaborator

Currently the LayoutPartialTree trait uses &mut self references when it needs write access to the tree (for writing cache entries and final layout values. This makes sense, however it a couple of downsides:

  • It makes it much harder for Taffy to use borrowed references to styles. We can only borrow between writes, and any time a write occurs we have to drop the reference and then reborrow even though in practice the style is never mutated by the cache write.
  • This API may not work for parallel layout if we ever implement multithreading.

We should investigate switching to using &self for all trait methods (which would imply the use of interior mutability on the implementors side). This implies a runtime cost but this may well end up not being significant (to be measured).

@nicoburns nicoburns added the usability Make the library more comfortable to use label Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usability Make the library more comfortable to use
Projects
None yet
Development

No branches or pull requests

1 participant