#1951·black

black performance scales non-linearly with the number of files to process

Author: asottileCreated Feb 1, 2021Updated Sep 28, 2026
LabelsT: bugC: performance

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

I suspect this is related to #1950 -- or at least exacerbated by it

setup

bash
rm -rf src
mkdir src
touch src/test_{1..10000}.py

1000 files

$ rm -rf t; time XDG_CACHE_HOME=$PWD/t black src/test_{1..1000}.py
All done! ✨  ✨
1000 files left unchanged.

real	0m1.504s
user	0m1.467s
sys	0m0.195s

10000 files

$ rm -rf t; time XDG_CACHE_HOME=$PWD/t black src/test_{1..10000}.py
All done! ✨  ✨
10000 files left unchanged.

real	0m55.354s
user	0m54.547s
sys	0m2.550s

I expect the second command to be approximately 10x slower than the first, however it's almost 30-40x worse

A guess is black is writing the cache for every single file and should instead batch it per run

Expected behavior A clear and concise description of what you expected to happen.

Environment (please complete the following information):

  • Version: [e.g. master] 71117e730c4f62458b30af820f51890487b458e4
  • OS and Python version: [e.g. Linux/Python 3.7.4rc1] 3.8.5 on ubuntu 20.04

Does this bug also happen on master? To answer this, you have two options:

yes

Additional context Add any other context about the problem here.