GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — events: handle inherited properties properly by thefourtheye · Pull Request #2350 · nodejs/node

Conversation

@thefourtheye

@thefourtheye thefourtheye commented Aug 11, 2015

Copy link
Copy Markdown
Contributor

As of now, the events module considers inherited properties as one of the
valid types, by default.

> process.version
'v3.0.0'
> events.EventEmitter.listenerCount(new events.EventEmitter(), 'toString')
1

This patch makes sure that the inherited properties are considered as
normal types and they will not be counted unless explicitly added.

> process.version
'v4.0.0-pre'
> events.EventEmitter.listenerCount(new events.EventEmitter(), 'toString')
0
> const emitter = new events.EventEmitter();
undefined
> emitter.on('toString', function() {});
EventEmitter {
  domain:
   Domain {
     domain: null,
     _events: { error: [Function] },
     _eventsCount: 1,
     _maxListeners: undefined,
     members: [] },
  _events: { toString: [Function] },
  _eventsCount: 1,
  _maxListeners: undefined }
> events.EventEmitter.listenerCount(emitter, 'toString')
1

I am guessing this would be a semver-major change, as this could be a breaking change.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@thefourtheye thefourtheye added events Issues and PRs related to EventEmitter and the events module. semver-major PRs that contain breaking changes and should be released in the next major version. labels Aug 11, 2015
@thefourtheye thefourtheye mentioned this pull request Aug 11, 2015
events: deprecate static listenerCount function #2349
Closed
@vkurchatkin

vkurchatkin commented Aug 11, 2015

Copy link
Copy Markdown
Contributor

nodejs/node-v0.x-archive#4366

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Aug 11, 2015

Copy link
Copy Markdown
Contributor Author

Oh. Performance hit. Okay, how about using a Map instead?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vkurchatkin

vkurchatkin commented Aug 11, 2015

Copy link
Copy Markdown
Contributor

#1785

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brendanashworth

brendanashworth commented Aug 13, 2015

Copy link
Copy Markdown
Contributor

Could someone run benchmarks on the entire new EventEmitter()?

The event emitter code is considered a red hot code path and obj = Object.create(null) is 20-30 times slower than obj = {}.

This doesn't seem to be benchmarking much, obj = {} could be a thousandth of the actual time spent creating the EE.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

brendanashworth
brendanashworth reviewed Aug 13, 2015
View reviewed changes
Comment thread test/parallel/test-event-emitter-listeners-side-effects.js Outdated

@brendanashworth brendanashworth Aug 13, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Is this a necessary change?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@thefourtheye

thefourtheye commented Aug 15, 2015

Copy link
Copy Markdown
Contributor Author

Closing in favour of #1785

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye thefourtheye closed this Aug 15, 2015
@thefourtheye
thefourtheye deleted the fix-for-event-listener-and-inherited-properties branch August 15, 2015 22:59
@thefourtheye thefourtheye mentioned this pull request Oct 22, 2015
EventEmitter: use a Map to store event listeners #1785
Closed
@thefourtheye thefourtheye mentioned this pull request Nov 14, 2015
util: use Object.create(null) for dictionary object #3791
Closed
@thefourtheye
thefourtheye restored the fix-for-event-listener-and-inherited-properties branch November 15, 2015 04:58
@thefourtheye

thefourtheye commented Nov 15, 2015

Copy link
Copy Markdown
Contributor Author

Reopening this thread as #1785 was shot down and Object.create is ten times slower than Object literal but the difference is a very small number. The script I used is at #1785 (comment) cc @nodejs/collaborators

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye thefourtheye reopened this Nov 15, 2015
@thefourtheye
events: handle inherited properties properly
85b2939
As of now, the events module considers inherited properties as one of the
valid types, by default.

    > process.version
    'v3.0.0'
    > events.EventEmitter.listenerCount(new events.EventEmitter(), 'toString')
    1

This patch makes sure that the inherited properties are considered as
normal types and they will not be counted unless explicitly added.

    > process.version
    'v4.0.0-pre'
    > events.EventEmitter.listenerCount(new events.EventEmitter(), 'toString')
    0
    > const emitter = new events.EventEmitter();
    undefined
    > emitter.on('toString', function() {});
    EventEmitter {
      domain:
       Domain {
         domain: null,
         _events: { error: [Function] },
         _eventsCount: 1,
         _maxListeners: undefined,
         members: [] },
      _events: { toString: [Function] },
      _eventsCount: 1,
      _maxListeners: undefined }
    > events.EventEmitter.listenerCount(emitter, 'toString')
    1
@thefourtheye
thefourtheye force-pushed the fix-for-event-listener-and-inherited-properties branch from a18b67e to 85b2939 Compare November 15, 2015 05:07
@mscdex

mscdex commented Nov 16, 2015

Copy link
Copy Markdown
Contributor

@thefourtheye I'm not seeing the same results that you described in that other issue. Here is what I get with current master and your benchmark script:

Object.create: 7359.860ms
Object Literal: 695.927ms
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@targos

targos commented Nov 16, 2015

Copy link
Copy Markdown
Member

I'm seeing the same kind of benchmark results but I'm not sure we can trust them. V8 may be smart enough to see that we don't do anything with the object literal and not create it at all.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@targos

targos commented Nov 16, 2015

Copy link
Copy Markdown
Member

@thefourtheye can you compare the EE benchmarks between master and master + this PR ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mscdex

mscdex commented Nov 16, 2015

Copy link
Copy Markdown
Contributor

@targos I just added code that interacts with obj in both scenarios and I still see the same results.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott
Trott force-pushed the master branch from 1e896a6 to 082cc8d Compare December 27, 2015 02:00
@jasnell jasnell added the stalled Issues and PRs manually marked as stalled and scheduled for automatic closure. label Mar 22, 2016
@jasnell

jasnell commented Mar 22, 2016

Copy link
Copy Markdown
Member

@thefourtheye ... is this still something you want to pursue?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Mar 25, 2016

Copy link
Copy Markdown
Contributor Author

@jasnell Yes, as this has to be fixed somehow. I'll close this now and open a separate PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye thefourtheye closed this Mar 25, 2016
@thefourtheye
thefourtheye deleted the fix-for-event-listener-and-inherited-properties branch March 25, 2016 09:55
@thefourtheye thefourtheye mentioned this pull request Apr 7, 2016
events: don't inherit from Object.prototype #6092
Merged
3 tasks done
@snyk-bot snyk-bot mentioned this pull request Jan 16, 2022
[Snyk] Security upgrade marked from 0.3.19 to 4.0.10 solebox/node#27
Open
This was referenced Jan 16, 2022
[Snyk] Security upgrade marked from 0.3.19 to 4.0.10 s4sc/node#26
Open
[Snyk] Security upgrade marked from 0.3.6 to 4.0.10 GregorFendt/node#20
Open
[Snyk] Security upgrade marked from 0.3.6 to 4.0.10 saurabharch/node#25
Open
[Snyk] Security upgrade marked from 0.3.6 to 4.0.10 KamilPolivka/node#24
Open
[Snyk] Security upgrade marked from 0.3.19 to 4.0.10 erdun/node#44
Open
[Snyk] Security upgrade marked from 0.3.6 to 4.0.10 saeedahassan/node#38
Open
[Snyk] Security upgrade marked from 0.3.6 to 4.0.10 olegnn/node#38
Open
@snyk-bot snyk-bot mentioned this pull request Jan 31, 2022
[Snyk] Security upgrade marked from 0.3.19 to 4.0.10 enterstudio/node#25
Open
@snyk-bot snyk-bot mentioned this pull request Jun 24, 2022
[Snyk] Fix for 7 vulnerabilities adamlaska/node#70
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

events Issues and PRs related to EventEmitter and the events module. semver-major PRs that contain breaking changes and should be released in the next major version. stalled Issues and PRs manually marked as stalled and scheduled for automatic closure.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@thefourtheye @vkurchatkin @brendanashworth @mscdex @targos @jasnell
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.