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

chore(lib): don't require domain by default #101

Merged
merged 1 commit into from
Dec 13, 2019

Conversation

mmarchini
Copy link
Contributor

Domains have an unwanted overhead on Node.js v12. The overhead is
observable just by requiring domain. To prevent that, we postpone
requiring domain until we are sure it's necessary (in which case it
was already required somewhere else).

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 98.346% when pulling 830b004 on mmarchini:dont-require-domain into e79fdf1 on restify:master.

@coveralls
Copy link

coveralls commented Dec 10, 2019

Coverage Status

Coverage increased (+0.02%) to 98.473% when pulling cb1ef62 on mmarchini:dont-require-domain into e79fdf1 on restify:master.

Domains have an unwanted overhead on Node.js v12. The overhead is
observable just by requiring `domain`. To prevent that, we postpone
requiring `domain` until we are sure it's necessary (in which case it
was already required somewhere else).
Copy link

@misterdjules misterdjules left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the code to handle domain properties leaking information might actually not be necessary anymore. See inline comments for more context.

@@ -157,8 +161,17 @@ function _getSerializedContext(err) {
_.omit(err, self._knownFields) :
{};

if (topLevelFields.domain instanceof domain.Domain) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be necessary anymore now that Node.js sets the domain property on objects as being non-enumerable for versions of node >= 12.0.0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we still need to support Node.js >= 10.x, and possibly older versions (like 8.x as indicated by the Travis config) though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should keep supporting all Node.js versions which are still active (8.x, 10.x, 12.x and 13.x)? If that's the case, it will take some time for us to leverage the changes introduced on v12 (out of curiosity, those changes are also part of the performance issues I found).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although 8.x goes EOL later this month, so we can drop that soon...

// We don't want to load domains just to check if topLevelFields.domain is
// a Domain instance, so first we make sure domains are already loaded.
if (EventEmitter.usingDomains) {
if (!domain) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can load this even more lazily by loading the domain module only when processing a .domain property on the topLevelFields object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but if we get here domains were already loaded somewhere else. Doing it here saves us a hasOwnProperty/in.

@mmarchini
Copy link
Contributor Author

cc @hekike @DonutEspresso

@DonutEspresso
Copy link
Member

lgtm!

@hekike
Copy link
Member

hekike commented Dec 13, 2019

Thanks! Released as restify-errors@8.0.2

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

Successfully merging this pull request may close these issues.

5 participants