From: Batuhan Taskaya Date: Tue, 16 Nov 2021 02:38:40 +0000 (+0300) Subject: black/parser: optimize deepcopying nodes (#2611) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/d7b091e762121ee38ca313ab25006abf4723d203?ds=sidebyside;hp=d7b091e762121ee38ca313ab25006abf4723d203 black/parser: optimize deepcopying nodes (#2611) The implementation of the new backtracking logic depends heavily on deepcopying the current state of the parser before seeing one of the new keywords, which by default is an very expensive operations. On my system, formatting these 3 files takes 1.3 seconds. ``` $ touch tests/data/pattern_matching_*; time python -m black -tpy310 tests/data/pattern_matching_* 19ms All done! ✨ 🍰 ✨ 3 files left unchanged. python -m black -tpy310 tests/data/pattern_matching_* 2,09s user 0,04s system 157% cpu 1,357 total ``` which can be optimized 3X if we integrate the existing copying logic (`clone`) to the deepcopy system; ``` $ touch tests/data/pattern_matching_*; time python -m black -tpy310 tests/data/pattern_matching_* 1ms All done! ✨ 🍰 ✨ 3 files left unchanged. python -m black -tpy310 tests/data/pattern_matching_* 0,66s user 0,02s system 147% cpu 0,464 total ``` This still might have some potential, but that would be way trickier than this initial patch. ---