Skip to content

Pr 379 bundling performance#389

Draft
ianmacartney wants to merge 5 commits intomainfrom
cursor/pr-379-bundling-performance-eae5
Draft

Pr 379 bundling performance#389
ianmacartney wants to merge 5 commits intomainfrom
cursor/pr-379-bundling-performance-eae5

Conversation

@ianmacartney
Copy link
Copy Markdown
Member

Add dynamic import validation to the bundler to reject dynamic imports in isolate files.

The added check introduces a negligible ~2-4% overhead to the total bundling pipeline, primarily due to an effective fast-path optimization that skips AST parsing for most files.


Slack Thread

Open in Web Open in Cursor 

This is a copybara of #379.

Changes:
- Add deploy-time validation that rejects import() expressions in Convex
  files that don't have a "use node" directive
- The check runs during bundling in entryPointsByEnvironment(), using
  @babel/parser AST analysis with a fast string pre-check
- Test files (.test.ts, .spec.ts) are already excluded from entry points
  by existing bundler logic and are unaffected

Performance impact (benchmarked):
- Fast-path optimization: files without 'import(' string skip AST parsing
- Typical overhead: 2-4% of total bundling time (~1-5ms for 50-200 files)
- esbuild dominates total time (20-50ms), so check overhead is negligible

Tests:
- Added unit tests for hasDynamicImport() covering various patterns
- Added integration tests for entryPointsByEnvironment() behavior

Co-authored-by: Ian Macartney <ianmacartney@users.noreply.github.com>
@cursor
Copy link
Copy Markdown

cursor bot commented Mar 3, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

cursoragent and others added 4 commits March 3, 2026 21:59
Co-authored-by: Ian Macartney <ianmacartney@users.noreply.github.com>
- Add 'use node' directive to import_tests.ts since dynamic imports work in Node.js
- Remove dynamicImportQuery which tested runtime failure (now caught at build time)
- Remove test_query_dynamic_import Rust test (no longer applicable)

The build-time validation replaces runtime errors with clearer deploy-time errors,
improving DX. Tests for runtime dynamic import failures in V8 isolates are no
longer needed since the bundler now prevents these cases.

Co-authored-by: Ian Macartney <ianmacartney@users.noreply.github.com>
Dynamic imports work fine in V8 isolate actions but fail in queries/mutations.
Updated the validation to only block dynamic imports in files that import
query, mutation, internalQuery, or internalMutation.

This preserves existing behavior where dynamic imports work in isolate actions
while still catching the case where they would fail at runtime in queries.

- Added importsQueryOrMutation() helper to detect query/mutation imports
- Updated hasDynamicImport check to also require query/mutation imports
- Restored original import_tests.ts without 'use node' since actions work
- Restored test_query_dynamic_import Rust test

Co-authored-by: Ian Macartney <ianmacartney@users.noreply.github.com>
The dynamicImportQuery test verified runtime failure of dynamic imports in
queries. Since files containing query/mutation imports with dynamic imports
are now blocked at build time, this runtime test is no longer needed.

The file now only contains actions (no query import), so it passes validation
since dynamic imports work fine in V8 isolate actions.

Co-authored-by: Ian Macartney <ianmacartney@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

2 participants