Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ruff_formatter: remove the mono-morphed code
This replaces the raw pointer type erasure with safe dynamic dispatch. I'm a little unsure about this since I don't quite understand why the code was written the way it was. In any case, I did a before-and-after benchmark comparison: $ critcmp main test group main test ----- ---- ---- formatter/large/dataset.py 1.00 1306.0±9.42µs 31.2 MB/sec 1.02 1328.5±6.89µs 30.6 MB/sec formatter/numpy/ctypeslib.py 1.00 271.3±2.78µs 61.4 MB/sec 1.02 276.3±1.88µs 60.3 MB/sec formatter/numpy/globals.py 1.00 21.8±0.18µs 135.1 MB/sec 1.04 22.7±0.18µs 129.9 MB/sec formatter/pydantic/types.py 1.00 522.1±4.08µs 48.8 MB/sec 1.01 529.7±3.90µs 48.1 MB/sec formatter/unicode/pypinyin.py 1.00 80.7±0.30µs 52.0 MB/sec 1.02 82.2±0.28µs 51.1 MB/sec I ran the benchmarks a few times, and the same result persisted. So it does seem like there is a very tiny regression here. Even so, I think it's worth it if we can remove the use of `unsafe` (and assuming there aren't any bigger regressions).
- Loading branch information