-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Reduces redundant clamping on labels #12905
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
Conversation
Thank you for the pull request, @mzschwartz5! ✅ We can confirm we have a CLA on file for you. |
This reverts commit 83eb415.
}); | ||
|
||
expect(l._clampedPosition).toBeDefined(); | ||
expect(l._glyphs[0].billboard._clampedPosition).toBeDefined(); |
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 removed this line because:
- Now that
updateClamping
is skipped for glyph billboards, this value is undefined. On changes to the label's clamped position, it will propagate to the glyph. But not on construction (not that it really matters - only for the sake of this test). - It wasn't a particularly robust test anyway, poking at the internal details of a label's glyph's billboard... we should be doing less of this.
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.
👍, expect(some._nested._private._property).toBe(42)
is an antipattern (not only in tests)
Maybe I could derive it by reading the surrounding code more thoroughly. But you likely have all that in the working memory right now, and maybe it's an easy question:
I see that this flag causes an early return in Totally unrelated: I stumbled over that
Regardless of that: Avoiding redundant work is good. Further optimizations could be related to reducing the work implied by |
What do you mean here? There's the octree picking PR, which I intend to pull across the finish line. In general, when I think "further optimizations" for labels, I would want to completely restructure it so glyphs aren't each their own billboard. But that would also require significant shader changes... ugh. |
On a very high level, there are structural similarities between the clamping performance ( #12719 ) and picking performance: #11814. Both functionalities are elaborately wired in without proper abstractions, they use an inefficient implementation, and they are called faaar too often. (And ... maybe I'm misremembering something, but isn't clamping (under certain conditions) even using some However, similar to the "caching" that was drafted in https://github.com/CesiumGS/cesium/tree/cache-model-picks to address the model picking performance, one could have further options if there was an abstraction for the clamping. The current patterrn of constructor(...scene...) {
this.scene = scene;
..
}
...
setHeightReference(...) {
this.heightReferece = value;
}
...
doTheClamping() {
if (this.heightReference !== NONE) {
if (this.scene === undefined) throw up; // Ouch...
const height = scene.getHeight(...);
} could benefit from some ...
setHeightProvider(...) {
this.heightProvider = value;
}
...
doTheClamping() {
if (this.heightProvider !== undefined) {
const height = this.heightProvider.getHeight(...);
}
} It would avoid the wrong ownership direction of a |
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 works much better. Thanks @mzschwartz5!
Description
Clamping things to ground is a slow operation (currently - #9961 will speed it up, but it's still relatively expensive). When a label is clamped to ground, it sets each of its glyphs (which are individual billboards) to clamp as well.
This is slow and unnecessary - we already have logic that copies the clamped position of the label to each of its glyphs.. It even claims to do this to reduce clamping redundancy, but unfortunately it's not sufficient.
To address the issue, this PR adds a new boolean flag to
Billboard
:positionFromParent
- when true, this flag indicates that the billboard gets its position from some ancestor, and thus expensive operations like clamping can be skipped. (I'm generally not a fan of adding special flags, but I considered a few other options and nothing was particularly simpler or feasible without a much larger refactoring effort. Happy to discuss alternative ideas though).Issue number and link
This is one piece of an overall labels performance improvement effort, stemming from #12719
Testing plan
Test with this sandcastle. Specifically, set labels to 1000, and toggle the number of characters between 5 and 100. Before this PR, there's a pretty big lag in creating / destroying the glyphs, and panning around is pretty intolerable as well. With this PR, it's noticeably faster (but still much room for improvement, which I plan to address).
Two notes:
Author checklist
CONTRIBUTORS.md
CHANGES.md
with a short summary of my change