Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issue: stripComments blocks event loop for 12s #1

Open
swarmiakimmo opened this issue Dec 20, 2021 · 3 comments
Open

Performance issue: stripComments blocks event loop for 12s #1

swarmiakimmo opened this issue Dec 20, 2021 · 3 comments

Comments

@swarmiakimmo
Copy link

swarmiakimmo commented Dec 20, 2021

We did a CPU profiling for our node app and noticed that the query normalization blocks event loop for quite a while:

146690398-ff776b3e-9cde-4521-8a2c-14999431c8b2

stripComments function was taking 12 seconds in one long SQL query we were using.

Wanted to report this for others possibly investigating the same, feel free to close. Unfortunately I don't have a reproducible query example.

@swarmiakimmo
Copy link
Author

Our workaround was to simply disable query normalisation.

@gajus
Copy link
Owner

gajus commented Dec 20, 2021

Can you share a query that was causing this?

@mvakula
Copy link

mvakula commented Dec 28, 2021

@gajus here's example test which reproduces the issue

test('parse long query', (t) => {
  const params = [...Array(30_000).keys()].map(i => `$${i}`).join(', ')
  const query = `
  SELECT 1
  FROM foo
  WHERE id IN (
    ${params}
  )
  `
  console.time('parse')
  const subject = stripComments(query)
  console.timeEnd('parse')
  t.true(true);
})

npm test will output

> [email protected] test
> NODE_ENV=test nyc ava --verbose --serial


  ✔ factories › createQueryNormalisationInterceptor › strips comments from the query

  ✖ Timed out while running tests

parse: 24.216s
  ─

  1 test passed

Ava test runner default timeout is 10s. I ran tests with macbook i9.

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

No branches or pull requests

3 participants