Skip to content
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

Cache loaded dom images on Image class so the playground-editor doesn't have to reload them often #13388

Merged
merged 5 commits into from
Jan 10, 2023

Conversation

carolhmj
Copy link
Contributor

Without the change:
ge-no-cache
With the change:
ge-cache

Copy link
Member

@RaananW RaananW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the data being disposed when the GUI is disposed?

Copy link
Member

@sebavan sebavan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this should be part of the Image class, could the cache be moved in the editor as it looks dedicated for it ?

@carolhmj
Copy link
Contributor Author

carolhmj commented Jan 3, 2023

I am not sure this should be part of the Image class, could the cache be moved in the editor as it looks dedicated for it ?

@sebavan this behavior isn't totally exclusive to the editor, as this would happen in any case where the control is repeatedly cleared and added to the parent. For example, this Playground: https://playground.babylonjs.com/#F2SG3A#2

Behaves like this now:
image-movement-gui-current

But with the cache:
image-movement-gui-new

@RaananW
Copy link
Member

RaananW commented Jan 3, 2023

My only comment is caching to a static object without clearing it when the image/scene/engine disposes. Not sure what would be the best dispose mechanism here, but it should be cleared for sure when the engine is disposed (otherwise it is technically a memory leak). Is it possible to dispose the data when an image is disposed?

@sebavan sebavan self-requested a review January 3, 2023 16:40
@kircher1
Copy link
Contributor

kircher1 commented Jan 3, 2023

@carolhmj, would this also remove the duplicated image requests for grass.png in this playground? https://playground.babylonjs.com/#XCPP9Y#16922

@carolhmj
Copy link
Contributor Author

carolhmj commented Jan 3, 2023

@carolhmj, would this also remove the duplicated image requests for grass.png in this playground? https://playground.babylonjs.com/#XCPP9Y#16922

@kircher1 I tested and it does remove the duplication! I'm just going to move this to be a ADT level cache so it doesn't leak memory :)

@carolhmj
Copy link
Contributor Author

carolhmj commented Jan 4, 2023

Cache was moved to the ADT! @RaananW @sebavan @kircher1

The only caveat is that, since we need to know to which ADT the image belongs to cache it, caching will only occur if img.source is set AFTER it is added to a control.

@carolhmj carolhmj requested a review from RaananW January 4, 2023 18:02
@bjsplat
Copy link
Collaborator

bjsplat commented Jan 4, 2023

Visualization tests for webgl1 have failed. If some tests failed because the snapshots do not match, the report can be found at

https://babylonsnapshots.z22.web.core.windows.net/refs/pull/13388/merge/testResults/webgl1/index.html

If tests were successful afterwards, this report might not be available anymore.

@sebavan sebavan self-requested a review January 4, 2023 23:56
@sebavan
Copy link
Member

sebavan commented Jan 4, 2023

The only caveat is that, since we need to know to which ADT the image belongs to cache it, caching will only occur if img.source is set AFTER it is added to a control.

ohhh yeah right, I wonder how often we actually set it after knowing it is a ctor parameter ?

Copy link
Member

@RaananW RaananW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @sebavan - i'll let you merge it after your concerns are addressed.

@carolhmj carolhmj requested a review from RaananW January 10, 2023 20:09
@carolhmj
Copy link
Contributor Author

@sebavan @RaananW updated to have the cache back as a static Image member, but we keep track of how many times that image is being used to clear it when it's not necessary anymore

@sebavan sebavan enabled auto-merge January 10, 2023 20:40
@sebavan sebavan merged commit b62a382 into BabylonJS:master Jan 10, 2023
@carolhmj carolhmj deleted the GECacheImages branch July 19, 2023 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants