Skip to content

formatWithCursor performance bottleneck #4801

@tmcw

Description

@tmcw

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:editor supportIssues about tools Prettier provides for use inside editor integrations.type:perfIssue with performance of Prettier

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions