{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/io.js/issues/2248","labels_url":"https://api.github.com/repos/nodejs/io.js/issues/2248/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/io.js/issues/2248/comments","events_url":"https://api.github.com/repos/nodejs/io.js/issues/2248/events","html_url":"https://github.com/nodejs/io.js/pull/2248","id":97226534,"number":2248,"title":"util: delay creation of debug context","user":{"login":"ofrobots","id":79017,"avatar_url":"https://avatars.githubusercontent.com/u/79017?v=3","gravatar_id":"","url":"https://api.github.com/users/ofrobots","html_url":"https://github.com/ofrobots","followers_url":"https://api.github.com/users/ofrobots/followers","following_url":"https://api.github.com/users/ofrobots/following{/other_user}","gists_url":"https://api.github.com/users/ofrobots/gists{/gist_id}","starred_url":"https://api.github.com/users/ofrobots/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ofrobots/subscriptions","organizations_url":"https://api.github.com/users/ofrobots/orgs","repos_url":"https://api.github.com/users/ofrobots/repos","events_url":"https://api.github.com/users/ofrobots/events{/privacy}","received_events_url":"https://api.github.com/users/ofrobots/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nodejs/io.js/labels/util","name":"util","color":"d4c5f9"},{"url":"https://api.github.com/repos/nodejs/io.js/labels/vm","name":"vm","color":"bfdadc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-25T13:22:37Z","updated_at":"2015-07-25T14:57:30Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/nodejs/io.js/pulls/2248","html_url":"https://github.com/nodejs/io.js/pull/2248","diff_url":"https://github.com/nodejs/io.js/pull/2248.diff","patch_url":"https://github.com/nodejs/io.js/pull/2248.patch"},"body":"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.\r\n\r\nI was really surprised by the number of ticks I got in `RunInDebugContext`. The full profile is [here](https://gist.github.com/ofrobots/3b031d8319e77acbfc0f) but here's an excerpt:\r\n\r\n```\r\n38    0.7%    0.7%  node::ContextifyContext::RunInDebugContext(v8::FunctionCallbackInfo<v8::Value> const&)\r\n```\r\n\r\nI 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.\r\n\r\nBased on my measurements, this saves ~24ms in node startup time measured as follows:\r\n\r\n```shell\r\n#!/usr/bin/bash\r\n# Note: this requires GNU date\r\nstart=$(date +%s%N)\r\nfor c in {0..60}\r\ndo\r\n  iojs -e \" \"\r\ndone\r\nnew=$(date +%s%N)\r\nelapsed=$(((new - start)/60))\r\necho $elapsed\r\n```\r\n\r\nThis 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\n\r\nR=@bnoordhuis, @monsanto \r\n\r\n"},"comment":{"url":"https://api.github.com/repos/nodejs/io.js/issues/comments/124852239","html_url":"https://github.com/nodejs/io.js/pull/2248#issuecomment-124852239","issue_url":"https://api.github.com/repos/nodejs/io.js/issues/2248","id":124852239,"user":{"login":"targos","id":2352663,"avatar_url":"https://avatars.githubusercontent.com/u/2352663?v=3","gravatar_id":"","url":"https://api.github.com/users/targos","html_url":"https://github.com/targos","followers_url":"https://api.github.com/users/targos/followers","following_url":"https://api.github.com/users/targos/following{/other_user}","gists_url":"https://api.github.com/users/targos/gists{/gist_id}","starred_url":"https://api.github.com/users/targos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/targos/subscriptions","organizations_url":"https://api.github.com/users/targos/orgs","repos_url":"https://api.github.com/users/targos/repos","events_url":"https://api.github.com/users/targos/events{/privacy}","received_events_url":"https://api.github.com/users/targos/received_events","type":"User","site_admin":false},"created_at":"2015-07-25T14:57:30Z","updated_at":"2015-07-25T14:57:30Z","body":"LGTM, the difference is huge !"}}