-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
formatWithCursor performance bottleneck #4801
Copy link
Copy link
Open
Labels
type:editor supportIssues about tools Prettier provides for use inside editor integrations.Issues about tools Prettier provides for use inside editor integrations.type:perfIssue with performance of PrettierIssue with performance of Prettier
Metadata
Metadata
Assignees
Labels
type:editor supportIssues about tools Prettier provides for use inside editor integrations.Issues about tools Prettier provides for use inside editor integrations.type:perfIssue with performance of PrettierIssue with performance of Prettier
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
formatWithCursorhas 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.