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

question. How setImmediate improve performance? #23

Closed
ChangJoo-Park opened this issue Mar 31, 2021 · 3 comments
Closed

question. How setImmediate improve performance? #23

ChangJoo-Park opened this issue Mar 31, 2021 · 3 comments

Comments

@ChangJoo-Park
Copy link
Contributor

Hello @pi0 . I can not find for place to question. So I leave my question here.

I saw yesterday your commit. I understood early return (break to return) is nice pattern in the upper diff src/app.ts.
but, I didn't understand to use setImmediate. All of request already asynchronous. Why need Promise with setImmediate ?

I tried to benchmark before / after setImmediate . I got almost same result.

@pi0
Copy link
Member

pi0 commented Mar 31, 2021

Hi @ChangJoo-Park. Nice that you checked :) To be honest I've not clear idea why. But you can try yarn profile script to see flame-graph (yarn build is required on a change). It seems event loop gets blocked for sending response without setImmediate. And BTW I've inspired deferring send from connect.

I tried to benchmark before / after setImmediate . I got almost same result.

What is you node version and testing method? For me it was order of 15 percent in node 14

@ChangJoo-Park
Copy link
Contributor Author

Thank you for reply! I retry with yarn profile Please see result below.
I use Node.js 14 on WSL. 0x cannot launch browser with 0x 😭 I'll fix script and rerun for my env.

image

image

I tried to benchmark before / after setImmediate . I got almost same result.

Before I try I saw only throughput. It slightly same.

weird result express with setImmediate

h3's the way of return response is just return something, It is not same with express.

So. I try express with this code. always 'just res.send' faster than with setImmediate.

app.get('/', (req, res) => {
  return res.send({ hello: 'world' })
})

image

app.get('/', (req, res) => {
  setImmediate(() => res.send({ hello: 'world' }))
})

image

@ChangJoo-Park
Copy link
Contributor Author

h3 use promise with setImmediate for nitro at this time. I understood this issue.

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

2 participants