-
-
Notifications
You must be signed in to change notification settings - Fork 345
Description
Description
When using createMiddleware(routing) with a large number of locales (100+), the next-intl middleware becomes extremely slow even in a minimal setup.
With ~140 locales in routing.locales, the middleware takes ~120–180 ms per request.
With only a few locales (<5), it runs in ~1–3 ms.
This slowdown happens:
- before any dictionary loading
- without any additional middleware logic
- in both dev and production builds
- with or without other integrations (Supabase, Auth.js, etc.)
This suggests that locale negotiation or internal matching scales linearly with the number of locales. Because only prefix detection + cookie + Accept-Language is needed, the middleware should not degrade significantly with a larger locale list.
This makes next-intl difficult to use in multilingual applications that support many regional variants (e.g. fr-FR, de-CH, en-GB, etc.).
Verifications
- I've verified that the problem I'm experiencing isn't covered in the docs.
- I've searched for similar, existing issues on GitHub and Stack Overflow.
- I've compared my app to a working example to look for differences.
Mandatory reproduction URL
https://github.com/lxup/next-intl-middleware-slow-repro
Reproduction description
Steps to reproduce:
- Open the reproduction repository.
- Notice that
supportedLocalescontains ~140 generated locales. - Start the dev server or run a production build.
- Load any page and check the console output in the server logs.
Observed:
- The line
Intl middleware took: XXX msconsistently reports ~150 ms. - Reducing the locale list to 3 items makes the middleware drop to ~1–2 ms.
Expected behaviour
The next-intl middleware should remain performant regardless of the number of supported locales.
Locale negotiation should be fast because it normally involves:
- Detecting a prefix
- Reading a cookie
- Optionally parsing Accept-Language
None of these operations require scanning every locale or performing heavy operations.
Expected:
- Middleware execution time should remain close to ~1 ms even with many locales (100+).
- Locale negotiation should not scale linearly with the number of locales.
- Apps supporting many regional locales should not suffer a 100–150 ms overhead per request.