Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
epaint: Memoize individual lines during text layout #5411
base: master
Are you sure you want to change the base?
epaint: Memoize individual lines during text layout #5411
Changes from 17 commits
622b848
150c0f6
db32a1e
4e3f162
3de1723
f028154
bc86bec
abbc561
6d6bc3b
6147ff3
66c83c3
1be24ba
fd8413c
bbe5662
110a9c3
139f286
e15b34b
c6592ec
25da822
40f237d
17a5f1f
c094ee8
3e1ed18
ec9a408
d2f75e9
2b53271
ba2ae9d
7fb85d1
9fa294f
77c9fd8
6b72d2f
b36311a
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functions is very long.
I would love if we could break this up into parts, for instance:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should such
LayoutJob::split_on_newlines
andGalley::concat
functions be public API or do we want to keep them private?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into splitting out these functions but it's actually non trivial, for example the splitting actually has to do the layout while it is doing the splitting because it has to update
LayoutJob::max_rows
as more rows are being laid out. As forGalley::concat
, it needs access topixels_per_point
for correct rounding so it'd be at the very least awkward as a public API (I guess you'd need to pass inFonts
?) and as a private one it could acceptFontsImpl
, it also needs access to the fullLayoutJob
so it can store it inside theGalley
and also to checkround_output_size_to_nearest_ui_point
.I think we could do something like a
Galley::concat(fonts: &mut FontsImpl, job: LayoutJob, galleys: impl Iterator<Item = Galley>) -> Galley
and keep splitting inGalleyCache::layout_multiline
or split it out into a method ofGalleyCache
but it has to have access toGalleyCache
so it can't be onLayoutJob
. Also at that point I don't know whether scattering the implementation detail ofFontsImpl
into aGalley
method is any more clean than keeping it inGalleyCache
.Maybe another solution would be to actually disable this line caching if
LayoutJob::max_rows
is finite, because in that scenario there's going to be more ways to invalidate the cached lines anyways and the performance benefits will be much more situational (any edit that will cause a line-count change will cause a re-layout of all subsequent lines). This could probably allow splitting out aLayoutJob::split_on_newlines
method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Splitting out the concatenation was pretty trivial:
9fa294f
(#5560)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree we can ignore
max_rows
for now (i.e. fall back to the old/slow path if it is set). Less bookkeeping of that and ofelided
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should also only do this if the text is long enough and/or actually contains newline characters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we can check for a '\n', initially I was skeptical but the actual layout is way more expensive than this string find will cost us so it's probably fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the newline part, I think adding a length check might not be worth it because it'd definitely make testing harder if an issue "only showed up if the text is longer than 1000 characters".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This deserves a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment, let me know if you feel this is sufficient or if you had something else in mind.