Skip to content

prettier.format() slow for deeply nested function calls in input string #4672

@tony19

Description

@tony19

When the input string contains many (about 25) nested function calls in JavaScript, prettier.format() takes about 2.5 minutes to return. This seems to occur when coreFormat() converts the AST to a document (in printAstToDoc()).

Environment:

  • macOS High Sierra 10.13.4
  • Node 8.9.4 and 9.11.1
  • MacBook Pro 2017, 2.7GHz i7, 16GB 2133MHz LPDDR3

Prettier 1.13.5
Playground link

Input:

_c("div", [
  _c("div", [
    _c("div", [
      _c("div", [
        _c("div", [
          _c("div", [
            _c("div", [
              _c("div", [
                _c("div", [
                  _c("div", [
                    _c("div", [
                      _c("div", [
                        _c("div", [
                          _c("div", [
                            _c("div", [
                              _c("div", [
                                _c("div", [
                                  _c("div", [
                                    _c("div", [
                                      _c("div", [
                                        _c("div", [
                                          _c("div", [
                                            _c("div", [_c("div", [_c("div")])])
                                          ])
                                        ])
                                      ])
                                    ])
                                  ])
                                ])
                              ])
                            ])
                          ])
                        ])
                      ])
                    ])
                  ])
                ])
              ])
            ])
          ])
        ])
      ])
    ])
  ])
])

Output:
(same as input after 159 seconds)

Expected behavior:
prettier.format(input) returns within a few seconds (much sooner than 159 seconds)

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.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