question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InteractionManager should cache interactionDOMElement.getBoundingClientRect

See original GitHub issue

mapPositionToPoint currently calls interactionDOMElement.getBoundingClientRect on every event.

Please see:

https://gist.github.com/paulirish/5d52fb081b3570c81e3a

This is expensive as it forces the browser to perform unnecessary style recalculations and may repaint any DOM elements/layers that are present outside of the PIXI canvas itself.

For apps/games that use only PIXI this isn’t much of an issue, but for any application that makes significant use of the DOM in addition to PIXI, this can be a big problem.

When I simply cache the result of getBoundingClientRect so that it doesn’t get called during each time an event fires, the issue is resolved and all of this extra work no longer occurs, potentially saving several ms each frame. On my 4K laptop, in an app with a lot of CSS and DOM elements, this can mean the difference between 25fps and 60fps.

This cache needs to be set in setTargetElement, and in the resize event.

I’m not certain this would be necessary, but potentially it may also be worth updating the cached values on pointerdown/mousedown also, so that it gets updated every time an interaction begins.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
englercjcommented, Apr 3, 2017

We could push the cache updating into userland, expose an API that refreshes the bound and it is up to the user to determine when/if they need to call it. I think the bounds being invalidated is not that common (maybe just resize).

0reactions
lock[bot]commented, Feb 24, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

InteractionManager should cache interactionDOMElement ...
When I simply cache the result of getBoundingClientRect so that it doesn't get called during each time an event fires, the issue is...
Read more >
Interaction Manager's - PixiJS API Documentation
* The interaction manager deals with mouse, touch and pointer events. *; * Any DisplayObject can be interactive if its `interactive` property is ......
Read more >
InteractionManager.ts - PixiJS
@pixi/mixin-cache-as-bitmap ... This will be set to true in * future versions of pixi. ... interactionDOMElement.style as CrossCSSStyleDeclaration; ...
Read more >
three.interaction.js API Documentation - GitHub Pages
autoAttach=true] - Should the manager automatically attach target element. ... @event InteractionManager#mousedown * @param {InteractionEvent} event ...
Read more >
Should I cache calls to .getBoundingClientRect() (in ...
Should I cache calls to .getBoundingClientRect() (in mousemove for ex) or the browsers do that? · Cyril Auburtin · Cyril Auburtin · PhistucK...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found