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

Allow Taffy to be used with f64 values where we currently f32 #332

Open
nicoburns opened this issue Jan 18, 2023 · 5 comments
Open

Allow Taffy to be used with f64 values where we currently f32 #332

nicoburns opened this issue Jan 18, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@nicoburns
Copy link
Collaborator

nicoburns commented Jan 18, 2023

What problem does this solve or what need does it fill?

I haven't had a chance to review in detail, but I can answer the f64 question. For a very large scrolling area, the scroll offset would lose precision (ie not even be able to represent an integer scroll offset) around 2^24. On CPU, the speed of doing f64 arithmetic is generally the same as f32.

linebender/xilem#37 (comment)

2^24 is 16,777,216 which seems very high. But I suppose that's not out of the range of a very long scroll region, and of course we also need to be able to represent decimal values.

What solution would you like?

Either:

  • Taffy should be made generic over the float type (allowing either f32 or f64 to be picked by the caller)
  • Or Taffy should just switch from f32 to f64

What alternative(s) have you considered?

Accept that Taffy won't work precisely at large sizes.

Additional context

We might want to think about how this interacts with #225 (which may want to add a pointer or slotmap key value to Dimension)

@nicoburns nicoburns added the enhancement New feature or request label Jan 18, 2023
@alice-i-cecile
Copy link
Collaborator

I'm nervous about swapping completely: doubling the memory usage does matter, both in games and on mobile.

@nicoburns
Copy link
Collaborator Author

A couple of notes on this one:

  • One option could be to use f64 for computation but still store f32. We'd need to benchmark, but I'd guess at f32 -> f64 conversion being cheap enough for this to be viable. If we turn Style into a trait then implementors of the API could choose how much precision they wish to store.
  • It's going to be hard to implement Support Calc val #225 without expanding dimension to fit 64 bit values. As calc() requires very large values which must therefore be boxed or similar likely requiring a usize sized value. We could potentially work around this by using a truncated index into a Vec/SlotMap or similar. But SlotMap doesn't currently support smaller keys either (Allow customization of key sizes orlp/slotmap#52) so we might need to implement our own storage. Also, if we use an index we'll need to carefully manage the lifecycle of the calc expressions, as it would be easy to leak them.

@nicoburns
Copy link
Collaborator Author

servo/servo#29819

@Loara
Copy link

Loara commented May 3, 2024

Instead to force f32 or f64 values I prefer to allow user to choose any "vector type" T that satisfies the following operations:

  • lossless addition between two T types;
  • lossy scalar multiplication between a T type and a scalar T::Scalar type (by default f64).

In this way you can use Layout also for TUI where dimensions must be integers or for "3D widgets" where instead dimensions are three-dimensional vectors.

@test3211234
Copy link

@Loara What is a 3D widget in TUI? I've never heard of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants