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

Optimize promise creation in em.populate #947

Open
stephenh opened this issue Jan 21, 2024 · 0 comments
Open

Optimize promise creation in em.populate #947

stephenh opened this issue Jan 21, 2024 · 0 comments

Comments

@stephenh
Copy link
Collaborator

stephenh commented Jan 21, 2024

Currently em.populate leverages the dataloader-driven batching of relations, and basically walks the tree of entities/relations calling .load.

This works, but it means every loaded relation creates a promise, which in a tree of ~10k-50k entities, can start to show up, in terms of runtime overhead.

We should be able to use the same approach as join/JSON preloading, which:

  • Doesn't actually flip relations to immediately loaded
  • Instead caches the relation key -> data in an internal cache
  • When relation.get is called, besides just isLoaded, we check isLoaded || data-in-cache

If done well, ideally this approach would mean we'd only have 1 promise per level/per wire call.

This can also explore removing the dependency on dataloader all together, because the biggest rationale for dataloader's "lots of promises" creation is to ensure each call site gets the information returned from the prior. Joist's em.populate doesn't actually need this, and we just need to know "okay loading is done", and then return the entities as-is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant