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

bug: default create-t3-turbo template is significant slower than create-t3-app #1279

Open
philippmossier opened this issue Jan 4, 2025 · 13 comments

Comments

@philippmossier
Copy link

philippmossier commented Jan 4, 2025

Provide environment information

System:
OS: macOS 14.6.1
CPU: (10) arm64 Apple M1 Max
Memory: 10.66 GB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.12.0 - ~/.local/state/fnm_multishells/11710_1735975103374/bin/node
Yarn: 1.22.22 - /opt/homebrew/bin/yarn
npm: 10.9.0 - ~/.local/state/fnm_multishells/11710_1735975103374/bin/npm
pnpm: 9.15.2 - /opt/homebrew/bin/pnpm
bun: 1.1.42 - /opt/homebrew/bin/bun
Watchman: 2024.09.30.00 - /opt/homebrew/bin/watchman

Describe the bug

🐛 Bug: t3-turbo API routes significantly slower than create-t3-app using the same Supabase setup

📝 Description

I've noticed a significant performance difference between the t3-turbo template and the create-t3-app template when interacting with the backend. Specifically, the post.create, post.all and post.getLatest routes take 1 to 1.4 seconds in t3-turbo, whereas similar API routes in create-t3-app take around 300 to 650 ms.


Update 11.Jan.2025 : Requests time are about 150ms for create-t3-app and 1000 -1300 ms for create-t3-turbo when removing the artifical delay (both use the same supabase DB connection)


Both projects were tested under similar conditions:

  • Database: Supabase (Postgres) using transaction pooler connection string.
  • ORM: Drizzle.
  • API Client: tRPC.
  • Network: Fast internet connection (~200 Mbps download, ~50 Mbps upload).
  • Location: Europe (matching the Supabase region).
  • Auth: Default auth setup via discord

Setup Route Time (ms)
t3-turbo post.all ~1000-1400ms
t3-turbo post.create ~1000-1300ms
create-t3-app post.getLatest ~300-650ms
create-t3-app post.create ~300-650ms

🖼️ Screenshots for Comparison

create-t3-app

image

🐢 t3-turbo

image

To reproduce

Steps to Reproduce

  • Create a new project using create-t3-turbo.
  • Set up the Supabase database and connect it using POSTGRES_URL.
  • Use the default Drizzle setup for database queries.
  • Test the post.create and post.all tRPC routes using browser dev tools.
  • Compare the performance against a similar setup using create-t3-app with the same database.
  • @juliusmarminge
    Copy link
    Member

    const waitMs = Math.floor(Math.random() * 400) + 100;

    @philippmossier
    Copy link
    Author

    Thanks for the quick reply. Haha, I didn’t expect an artificial delay. Of course, removing the delay helps, but I’m still surprised that the requests take almost 1 second. Combined with the refetching of post.all, it takes nearly 2 seconds until the new post appears in the list.

    Implementing optimistic updates helps here, but these response times still feel unusually slow to me. Am I missing something, or is this stack just not the fastest by design?

    image

    My database latency is consistently under 30ms, which seems fine. I still haven’t been able to figure out what’s causing this slow response.

    @juliusmarminge
    Copy link
    Member

    juliusmarminge commented Jan 4, 2025

    trpc's overhead should be minimal, so unless there's something else that's taking time in your resolver it should be fast and definetely not slower than create-t3-app

    @philippmossier
    Copy link
    Author

    Performance Comparison: create-t3-app vs create-t3-turbo

    I haven't changed anything except for the .env file in both projects.

    For create-t3-app, I removed the artificial delay, and now I get good response times around 110-150 ms.


    create-t3-app response time with Supabase (Postgres) using transaction pooler connection string

    create-t3-app response time

    I think 150 ms is acceptable for a Supabase database connection (compared to ~50 ms for a local Postgres DB).


    However, with create-t3-turbo, I still get 900 ms to 1300 ms response times using the same Supabase connection.


    create-t3-turbo response time for the same Supabase DB connection

    create-t3-turbo response time

    The create-t3-turbo project is nearly 1 second slower than create-t3-app with the exact same Supabase connection. 😞

    @juliusmarminge
    Copy link
    Member

    Do you have auth on both projects?

    @philippmossier
    Copy link
    Author

    Do you have auth on both projects?

    Yes on both I use discord auth

    @juliusmarminge
    Copy link
    Member

    And both have middleware?

    @philippmossier
    Copy link
    Author

    And both have middleware?

    Sorry I don't know what you mean by that. I have not added any additional middlerware. I am just using the out of the box discord auth, which means I have just added AUTH_DISCORD_ID and AUTH_DISCORD_SECRET to .env (also added http://localhost:3000/api/auth/callback/discord rediredt uri inside discord developer portal) and the authentication worked.

    @juliusmarminge
    Copy link
    Member

    i mean does both apps have a src/middleware.ts file? just trying to understand what might be differenet

    @philippmossier
    Copy link
    Author

    i mean does both apps have a src/middleware.ts file? just trying to understand what might be differenet

    only the t3-turbo app has a src/middleware.ts

    @philippmossier
    Copy link
    Author

    philippmossier commented Jan 5, 2025

    I debugged further and also added indexes to the schema.ts, similar to the create-t3-app schema, but there was no noticeable improvement in performance. Since the posts.all procedure is also taking around 1 second to complete and it’s a public procedure, I don’t think the issue is related to the auth middleware.

    I have created plenty of fresh DBs, played around with drizzle config and also created new fresh create-t3-app and create-t3-turbo, but create-t3-turbo's response time are always 1 second slower than create-t3-app, no matter what I do.

    I’m still new to this stack-setup, so I can’t say much more at this point. If I find anything, I’ll keep you updated.

    In the meantime, is there an older branch I could check out that might not have this performance issue?

    @philippmossier philippmossier changed the title bug: t3-turbo API routes significantly slower than create-t3-app using the same Supabase setup bug: default create-t3-turbo template is significant slower than create-t3-app Jan 11, 2025
    @ImBIOS
    Copy link

    ImBIOS commented Jan 28, 2025

    i mean does both apps have a src/middleware.ts file? just trying to understand what might be differenet

    only the t3-turbo app has a src/middleware.ts

    middleware.ts will significantly add response time. you should make both dev env the same and as identical as possible.

    give reproducable repo if possible.

    @philippmossier
    Copy link
    Author

    i mean does both apps have a src/middleware.ts file? just trying to understand what might be differenet

    only the t3-turbo app has a src/middleware.ts

    middleware.ts will significantly add response time. you should make both dev env the same and as identical as possible.

    give reproducable repo if possible.

    Hi thanks for the answer.

    I just cloned both t3 repos (create-t3-turbo and create-t3-app) and changed nothing besides the .env so that I can use discord auth and a subapase DB.
    Both use the same connection strings of the DB but create-t3-turbo adds almost 1 second additional response time.

    The middleware.ts file of create-t3-turbois also the default one after cloning (which anyway just holds a config with a matcher string for some next image related stuff)

    I have still no idea where this 1 additonal second of response time comes from :S

    I planned to provide a reproducable repo, but I wasn't able to use a local docker postgres with create-t3-turbo, but I would bet even then create-t3-turbo is almost 1 second slower than create-t3-app

    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

    3 participants