Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Formatting is very slow for deeply nested callbacks #426

Closed
rickyvetter opened this issue May 26, 2021 · 4 comments
Closed

Formatting is very slow for deeply nested callbacks #426

rickyvetter opened this issue May 26, 2021 · 4 comments

Comments

@rickyvetter
Copy link

Deeply nested callbacks seem to slow performance greatly. A file like this takes 2+s to format on my machine and only a couple more layers are needed for a format to seemingly never complete.

let a = () => {
  b(() => {
    c(() => {
      d(() => {
        e(() => {
          f(() => {
            g(() => {
              h(() => {
                i(() => {
                  j(() => {
                    k(() => {
                      l(() => {
                        ()
                      })
                    })
                  })
                })
              })
            })
          })
        })
      })
    })
  })
}

I am pretty sure this is an issue on the printing side. I get syntax errors and type errors immediately so the parser doesn't appear to have any problem with code like this.

Additionally, adding more logic in deeper layers leads to pretty large increases. So having one additional line in the inner-most callback slows things down much more than one layer up (which is better than two layers up). This seems to be a ~linear increase based on which layer you're in. While adding layers seems to be quadratic.

@cristianoc
Copy link
Contributor

There's an issue for that already. Looking.

@cristianoc
Copy link
Contributor

#261

@IwanKaramazow
Copy link
Contributor

Out of curiosity, what kind of code is this? machine generated? (still going to fix the underlying problem regardless of the code)

@rickyvetter
Copy link
Author

We saw this with deeply nested promises with custom resolution logic. It was handwritten - I think two levels less deep but lots more logic in it. ~7s to format ~400 lines.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants