Skip to content

Conversation

jpnickolas
Copy link
Contributor

@jpnickolas jpnickolas commented Sep 15, 2025

If you have large responses (e.g. 30k+ entities with 15k+ included values), then deserialization can take 3s+.

This is primarily due to the following line causing us to have an O(n) lookup - leading to an overall O(n^2) deserialization time:

const foundResource = included.find((item) => item.type === type && item.id === id)

By putting all of our included fields into an object keyed by type and then id, we can drop deserialization time from 3s+ to ~100ms for large responses like the one mentioned above.

@jpnickolas jpnickolas marked this pull request as ready for review September 15, 2025 19:01
@jpnickolas
Copy link
Contributor Author

@andersondanilo, would you be able to review this? 🙏

@jpnickolas
Copy link
Contributor Author

🤜 @andersondanilo bumping again

@andersondanilo andersondanilo force-pushed the master branch 2 times, most recently from 34c6274 to ca494e0 Compare September 30, 2025 23:01
@andersondanilo andersondanilo changed the title Improve join time of included fields by using a map instead of a Array.find fix: Improve join time of included fields by using a map instead of a Array.find Sep 30, 2025
@andersondanilo andersondanilo merged commit 6b2aabb into andersondanilo:master Sep 30, 2025
5 checks passed
github-actions bot pushed a commit that referenced this pull request Sep 30, 2025
## [2.3.2](v2.3.1...v2.3.2) (2025-09-30)

### Bug Fixes

* Improve join time of included fields by using a map instead of a Array.find ([#246](#246)) ([6b2aabb](6b2aabb))
Copy link

🎉 This PR is included in version 2.3.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@andersondanilo
Copy link
Owner

Nice! thank for your contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants