optimize ApiFromModules type performance #76
+12,705
−71
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request optimizes
ApiFromModules
and adds type-level benchmarks using@ark/attest
so that they can be tested and added to CI if desired.A large portion of the diff will consist of
fake_chef
files copied from a generated Convex project as a realistic benchmark and can generally be ignored. All meaningful optimizations occurred insrc/server/api.ts
.The biggest improvements come from avoiding the creation of intermediate object types, additional intersections, and adding a fast path for modules with no segmented (i.e.
A/B
) paths.This lead to a ~27% improvement in type performance on the fast path and ~14% for segmented modules. Similar strategies could be applied to other types in the repo for further improvements, but generally I found the types I reviewed to be relatively efficient and well-written, so props to the team 👏
As mentioned to @thomasballinger, another promising avenue for followup type optimization would be deduplicating object literals defined in
_generated/api.d.ts
. Here's an example of how that could be achieved:Applying a similar approach to a large number of object literals in Prisma's generated types led to a ~50% performance improvement, so this could be very impactful for large projects with many such components.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.