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

GLTFLoader parser.associations refactor #25252

Closed
elalish opened this issue Jan 6, 2023 · 5 comments
Closed

GLTFLoader parser.associations refactor #25252

elalish opened this issue Jan 6, 2023 · 5 comments
Labels

Comments

@elalish
Copy link
Contributor

elalish commented Jan 6, 2023

Description

<model-viewer> has two open issues that trace back to errors in parser.associations: google/model-viewer#3287 (comment), and google/model-viewer#4029

The second turns out to be caused by ReduceAssociations() being called for multiple scenes, which was introduced here to handle a memory leak: #22583. I believe these kinds of errors will keep cropping up unless we can simplify the associations.

Solution

I think a better approach for avoiding memory leaks would be to make the associations into a WeakMap instead of a Map. Then we could remove ReduceAssociations() entirely and not worry about having entries for extra clones. This is a breaking change and I'll have to refactor MV a bit for it, but since associations isn't documented I think @takahirox is the main other user of it, so I'm mostly looking for his opinion. @donmccurdy, hopefully you'll appreciate the simplification here.

Alternatives

Just fix these bugs in place, but I fear the code will get even more convoluted and will continue to be prone to memory leaks.

Additional context

No response

@donmccurdy
Copy link
Collaborator

This is a breaking change and I'll have to refactor MV a bit for it...

I don't think I see what makes this a breaking change, wouldn't the API be the same, and the contents of the association would be a superset of what it is now?

/cc @drcmda in case this affects R3F or gltfjsx

@elalish
Copy link
Contributor Author

elalish commented Jan 6, 2023

Well, it's a breaking change for me because I was looping through the keys of the Map, which you can't do with a WeakMap. But yeah, it's not a huge change.

@takahirox
Copy link
Collaborator

takahirox commented Jan 7, 2023

I'm a bit too busy now and haven't deeply thought yet but changing Map to WeakMap sounds ok to me. And we may add the note to the migration guide.

@donmccurdy
Copy link
Collaborator

Sounds good to me as well. 👍🏻

@donmccurdy
Copy link
Collaborator

PRs would still be welcome, but no current plans to implement this.

@donmccurdy donmccurdy closed this as not planned Won't fix, can't repro, duplicate, stale Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants