-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
I've isolated a bottleneck from our production environment and here's a nifty self-contained benchmark for it: https://gist.github.com/tmcw/1a4e8ee47941454337dc5952dbf90180 (swap require('./') for require('prettier') if that's intended)
What I'm seeing in this and in testing different cases is that formatWithCursor has a huge performance penalty over format, and it's entirely rooted in the call to diff.diffArrays, which creates may intermediate objects and arrays. The further into the document the cursor is, the more of a problem it becomes. This testcase takes upwards of 14s to format about 300 lines of code.
Reading the code, it's a bit insidery - I suspect that an approach that doesn't require a char array, or does the diff progressively with the checking, or skips the creation of so many intermediate objects, may be ideal.