Skip to content

feat: typegen concurrency#156

Open
atilafassina wants to merge 8 commits intomainfrom
typegen/perf-refactor
Open

feat: typegen concurrency#156
atilafassina wants to merge 8 commits intomainfrom
typegen/perf-refactor

Conversation

@atilafassina
Copy link
Contributor

@atilafassina atilafassina commented Mar 4, 2026

Run all queries concurrently.

In Dev Playground app (9 queries), this speeds up typegen from ~93 seconds to ~3 seconds
That's about ~30x faster

Before

[appkit:server] Mode: development (Vite HMR)
  appkit:server Remote tunnel: blocked; inactive +0ms
  Describing 9 queries (1/9)       ✓ app_activity_heatmap
  Describing 9 queries (2/9)..     ✓ apps_list
  Describing 9 queries (3/9).      ✓ cost_recommendations
  Describing 9 queries (4/9)...    ✓ example
  Describing 9 queries (5/9).      ✓ spend_data
  Describing 9 queries (6/9)...    ✓ spend_summary
  Describing 9 queries (7/9).      ✓ sql_helpers_test
  Describing 9 queries (8/9)       ✓ top_contributors
  Describing 9 queries (9/9)..     ✓ untagged_apps
  Described 9 queries (9/9)
  appkit:type-generator:query-registry 9 new queries, 0 cached, 0 failed. Typegen: 93.28s +93.3s

Now

[appkit:server] Mode: development (Vite HMR)
  appkit:server Remote tunnel: blocked; inactive +0ms
  Describing 9 queries (5/9)..     ✓ app_activity_heatmap
    ✓ apps_list
    ✓ cost_recommendations
    ✓ example
    ✓ spend_data
    ✓ spend_summary
    ✓ sql_helpers_test
    ✓ top_contributors
    ✓ untagged_apps
  ✓ Described 9 queries
  appkit:type-generator:query-registry 9 new queries, 0 cached. Typegen: 3.02s +3.0s

Improvements breakdown

Reducing network latency

  • Run queries in batches of 20 (avoids rate-limiting and sets good and safe concurrency out-of-the-box)

Reduce FS io

  • Read all query files concurrently from system to prepare query batch

Bonus
Add a perf measurement on debug to summarize cache HIT/MISS and time spent querying.


did some TUI consistency work so logs look similar.

Screenshot 2026-03-05 at 16 09 27

@atilafassina atilafassina changed the title feat: parallelize describe queries feat: typegen concurrency Mar 4, 2026
@atilafassina atilafassina marked this pull request as ready for review March 4, 2026 12:09
Copilot AI review requested due to automatic review settings March 4, 2026 12:09
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves AppKit’s type generator performance by parallelizing query schema discovery (DESCRIBE QUERY) and moving filesystem/cache operations to async APIs, reducing end-to-end type generation time in dev.

Changes:

  • Add concurrent, batched DESCRIBE execution with cache writes per batch and consolidated spinner output.
  • Switch cache, query reading, and output writing to node:fs/promises.
  • Extend CLI spinner with an update() method and update unit tests for the new async/concurrent behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
packages/appkit/src/type-generator/vite-plugin.ts Replace fs.existsSync usage with existsSync import.
packages/appkit/src/type-generator/tests/generate-queries.test.ts Update tests/mocks for async fs, spinner updates, and batching behavior.
packages/appkit/src/type-generator/spinner.ts Add Spinner.update() for progress text updates during concurrent runs.
packages/appkit/src/type-generator/query-registry.ts Implement parallel query file reads and batched concurrent DESCRIBE execution with cache updates.
packages/appkit/src/type-generator/index.ts Use async writeFile for generated type declarations.
packages/appkit/src/type-generator/cache.ts Convert cache load/save to async and use node:fs/promises.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@atilafassina atilafassina self-assigned this Mar 4, 2026
@atilafassina atilafassina added the enhancement New feature or request label Mar 4, 2026
@MarioCadenas
Copy link
Collaborator

I don't know if its something from my terminal but the progress doesn't show properly, once it finishes it doesn't update the first describing queries (x/x)...

image image

@atilafassina atilafassina force-pushed the typegen/perf-refactor branch 2 times, most recently from 6098b03 to c46d800 Compare March 5, 2026 16:09
@atilafassina atilafassina force-pushed the typegen/perf-refactor branch from c46d800 to e9ac4ca Compare March 5, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants