Remove all WITH_* flags from _imaging.c and other flags by homm · Pull Request #8211 · python-pillow/Pillow
I've tried to measure performance penalty for saving state.
Empty function call:
In [2]: %timeit Image.core.test_threading() 64.1 ns ± 0.842 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
With ImagingSectionEnter/ImagingSectionLeave:
In [6]: %timeit Image.core.test_threading() 109 ns ± 0.951 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)