Skip to content

whitenoise's scantree slows down test suite performance #558

Description

@codingjoe

Python Version

3.12

Django Version

4.2

Package Version

5.3.0

Description

Hi there 👋 and happy 2024,

We are switching to service ESM, rather than bundling our dependencies. Mainly, because updating once dependency will invalidate the cache for a whole bundle.

While doing so, I noticed that our test suite drastically decreased in performance. The reason, whitenoise will scan the entire STATIC_ROOT directory on every single client request causing significant disk IO.

That's bearable on a MacBook Pro with 1 GB/s disk speed and a large disk cache. On an Ubuntu worker on GitHub actions, we saw a 10x performance decrease. Taking our 8 min. test suite to a crisp 80 minutes.

I would propose moving the files dictionary from the middleware instance to the module or the thread.

The current implementation does not affect regular request service, since Middleware instances are not recycled. However, they are when you use a test client.

Until this is addressed, the only way I see to mitigate this behavior is to remove the middleware in your test suite:

# settings.py
TEST = os.getenv('TEST')
if TEST:
    # https://github.com/evansd/whitenoise/issues/558
    MIDDLEWARE.remove("whitenoise.middleware.WhiteNoiseMiddleware")

Love your thoughts!

Cheers, Joe

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions