Skip to content

next-intl middleware extremely slow with large number of locales (~140+) #2116

@lxup

Description

@lxup

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

Mandatory reproduction URL

https://github.com/lxup/next-intl-middleware-slow-repro

Reproduction description

Steps to reproduce:

  1. Open the reproduction repository.
  2. Notice that supportedLocales contains ~140 generated locales.
  3. Start the dev server or run a production build.
  4. Load any page and check the console output in the server logs.

Observed:

  • The line Intl middleware took: XXX ms consistently 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:

  1. Detecting a prefix
  2. Reading a cookie
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions