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

util: delay creation of debug context #2248

Closed
wants to merge 1 commit into from

Conversation

ofrobots
Copy link
Contributor

Now that it is really simple to take profiles with node (thanks to #2090), I was looking a profile I got from a trivial JSON.stringify benchmark.

I was really surprised by the number of ticks I got in RunInDebugContext. The full profile is here but here's an excerpt:

38    0.7%    0.7%  node::ContextifyContext::RunInDebugContext(v8::FunctionCallbackInfo<v8::Value> const&)

I looked into this. It seems that #1471 introduced a change which now creates a Debug context by default in the util module. This is needed to be able to inspect promises. I think this is fine, but we should not be doing the really expensive operation of creating a Debug context on default startup of node. This patch fixes that.

Based on my measurements, this saves ~24ms in node startup time measured as follows:

#!/usr/bin/bash
# Note: this requires GNU date
start=$(date +%s%N)
for c in {0..60}
do
  iojs -e " "
done
new=$(date +%s%N)
elapsed=$(((new - start)/60))
echo $elapsed

This reduces startup time from ~90ms → ~66ms on my machine. I think it is important that node startup is as fast as possible. I don't like deferred initialization as I am proposing, but I think it is a much lesser evil than spending 24ms on each node startup.

R=@bnoordhuis, @monsanto

We need the debug context to be able to inspect promises. However, this is
very expensive and should not be done on default startup.
@mscdex mscdex added util Issues and PRs related to the built-in util module. vm Issues and PRs related to the vm subsystem. labels Jul 25, 2015
@mscdex
Copy link
Contributor

mscdex commented Jul 25, 2015

LGTM

@targos
Copy link
Member

targos commented Jul 25, 2015

LGTM, the difference is huge !

@bnoordhuis
Copy link
Member

LGTM. Obvious in hindsight.

@Fishrock123
Copy link
Contributor

So does this mean that the first time you console.log a promise it'l take like 24ms?

@monsanto
Copy link
Contributor

LGTM

@rvagg
Copy link
Member

rvagg commented Jul 27, 2015

@ofrobots
Copy link
Contributor Author

@Fishrock123 Yes, it is going to be expensive for the first promise that is inspected.

@cjihrig
Copy link
Contributor

cjihrig commented Jul 27, 2015

Definitely worth the tradeoff IMO. LGTM.

@ofrobots
Copy link
Contributor Author

The CI looks decent to me, ignoring the flaky failures. I will land this later today.

ofrobots added a commit that referenced this pull request Jul 28, 2015
We need the debug context to be able to inspect promises. However, this is
very expensive and should not be done on default startup.

PR-URL: #2248
Reviewed-By: Brian White <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Christopher Monsanto <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
@ofrobots
Copy link
Contributor Author

Landed in ab47965.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
util Issues and PRs related to the built-in util module. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants