-
Notifications
You must be signed in to change notification settings - Fork 118
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
measure_func is called too many times when minWidth/maxWidth is involved #555
Comments
@vkurchatkin-miro You can try this branch #556. However, I would probably still recommend using your own caching for text. #490 should allow you to do this without Also, are you trying to use a browser's text layout with taffy-in-wasm? Because I suspect that will always be quite slow. If you use something like cosmic-text for text layout then I believe text layout should be relatively cheap (as splitting the text into runs can happen once, and relayout just needs to pack those runs into the specified width constraint). |
@nicoburns do you recommend switching to
Sure, that would be great when it is merged
I use
What makes you think that? I mean, it is slower then I would like it to be, but Taffy itself seems significantly slower than I expect it to be as well. That is in general very unfortunate, because in my current stress test involving 50000 nodes (~15000 text nodes) layout takes roughly 90% of all CPU time. |
Oh, by "browser's text layout" you mean something like |
We should be putting out a new release soon :) We're generally pretty active with those, but feel free to ping us if it's ever a hassle for you. |
Thanks. But there is still a question about this behaviour:
2 and 3 call seem strictly redundant. During first call we already have known width and out of that we can figure out the appropriate height |
That's often true, but not always. Consider the case of vertical text where the width is derived from the height rather than the other way around (a "column wrap" flexbox container also has this behaviour). I think it would be appropriate for you to implement your own cache for this (within the measure function) that takes advantage of the extra knowledge your code has about the content you are measuring. |
Thanks @nicoburns, it makes perfect sense, my statement is only valid if it is known that internal layout is left-to-right with wrapping. But still, what I fail to understand is how can known width turn into
I'm definitely going to do that. |
I believe that was actually a bug that was fixed by #545 (released in
It really means, "please layout the contents of this node and tell me what the height is assuming the the width is fixed at this size". This may be because the node has |
taffy
version0.3.13
Platform
WASM
What you did
I can try to make a standalone reproduction, but here is a structure that I have:
What went wrong
measure_func
is called 7 times. Here is a log of calls:Some of the calls make no sense at all, e.g. after there is a known
height
it still gets called without knownheight
. If I replaceminWidth
andmaxWidth
withwidth
I only get 3 calls:Although it still doesn't make much sense why there is a call without known height after there is a call with it.
Additional information
Text layout is very resource demanding and I would really like to reduce calls to it as much as possible. It is unclear to me how it should work with
minWidth
/maxWidth
(I understand if spec demands some shenaningans in this case, but 7 calls seem excessive), but in case of predefined width one call is definitely enough to figure the final.For now it seems like the only way is caching, but even that is unpleasant, since the only way to pass something to
measure_func
isRc<RefCell<>>
or something like thisThe text was updated successfully, but these errors were encountered: