-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix: labelDimCache #3298
Fix: labelDimCache #3298
Conversation
Pro: smaller, simpler Con: slower on graphs where you toggle styles Ref: Node label flickering when animating font-size #3270
@likeamike, does this address #3270 for you? |
@mikekucera, do you think this would be worth merging in for the next patch release? I'd like to have it decided which PRs we're going to include so I can coordinate with the upcoming PR for the build system. I don't want to deal with lots of merge conflicts, so applying or (reapplying) my changes on top of everything we want included would be best. Thanks |
Just a note: This issue might be more widespread than just the use case indicated in #3270. If the old approach can generate invalid cache values for the label dimensions, then it could mess up all the label texture calculations for canvas and WebGL. So I suspect it would be better to include this PR in the upcoming release, unless you have any reservations. |
Hi Max, The labelDimCache used to have one entry for every label (when there's no animation). That way label dimensions are only calculated once per label. |
Yes, that's a good point. Here's the approach in the PR: (1)
The old approach: (2)
Another approach: (3)
An expensive approach: (4)
What do you think? |
I think using one cached value per element in (1) would probably be the simplest and most reliable, even if it’s not the most efficient. (Do you even need a key if the bounds are stored on the element itself?) It has the disadvantage that if different nodes have the same label style then the bounds are recalculated for each instance, but I think that’s probably ok. The need is to avoid recalculating bounds on successive frames, not necessarily avoiding recalculating the same labels on the same frame. Lots of networks have unique labels for each node anyway. I do think this solution is more addressing the symptom than the root cause. Hash keys shouldn’t be colliding so easily. The hash function should be producing keys with a uniform distribution. But changing the hashing is high risk and I shied away from it myself. P.S. Edges actually need up to 3 labels right? |
Looking at this a bit more, I think the simplest approach along the lines of (1) would be to remove the caching/hashing in this function altogether. It looks like it may be a carryover from when we didn't have higher-level caching / rendered style invalidation. Currently, this function is only called in two ways: (a) For calculating the label dimensions for rendering. These values are (already) stored/cached per-element and used in higher-level functions. (In the case of edges, 3 -- source, target, and mid labels) (b) For calculating multi-line labels (wrapping, automatic ellipsis). For the normal flow (a), removing the caching (i.e. labelDimCache) would only incur a performance penalty when the style of an element changes but the label happened to remain exactly the same in text and styling. For multi-line calculations (b), you can't use a per-element cached value anyway. You have to check based on the words. I'm not sure caching the intermediate multi-line values would be worth the space/time trade-off either. So what do you think about just removing the caching from this function (
Yes. The hash function also has to be cheap and work with the limitations of JS (e.g. bitwise ops treat a number as a 32-bit int).
Yes |
Or the dimensions of the labels should be cached only in the higher-level |
Ref: cytoscape.js/src/extensions/renderer/base/coord-ele-math/labels.js Lines 298 to 320 in 5623dea
|
Cross-references to related issues. If there is no existing issue that describes your bug or feature request, then create an issue before making your pull request.
Associated issues:
Notes re. the content of the pull request. Give context to reviewers or serve as a general record of the changes made. Add a screenshot or video to demonstrate your new feature, if possible.
Checklist
Author:
unstable
. Bug-fix patches can go on eitherunstable
ormaster
.Reviewers:
master
branch and theunstable
branch. Normally, this just requires cherry-picking the corresponding merge commit frommaster
tounstable
-- or vice versa.