choojs / choojs/nanobus

Prossible perf_hooks memory leak detected

Open
#32 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
228
Forks
20
PR merge metrics
No merged PRs in 30d

Description

It seems nanobus creates a performance entry on event emit and never clear the entry, so after a long time of using, more and more entries of performance will be in memory.

key code here:
```js
var emitTiming = nanotiming(this._name + "('" + eventName + "')")
var listeners = this._listeners[eventName]
if (listeners && listeners.length > 0) {
this._emit(this._listeners[eventName], data)
}

if (this._starListeners.length > 0) {
this._emit(this._starListeners, eventName, data, emitTiming.uuid)
}
emitTiming()
```
and warning message is:
```
(node:84217) Warning: Possible perf_hooks memory leak detected. There are 996 entries in the Performance Timeline. Use the clear methods to remove entries that are no longer needed or set performance.maxEntries equal to a higher value (currently the maxEntries is 150).
```

and my test code is here:
```js
const nanobus = require('nanobus')
const bus = nanobus()

bus.on('foo', () => {})

for (let i=0; i<1000; i++) {
bus.emit('foo', 'bus')
}
```

I see this message when I use webpack-serve which use nanobus as bus to emit events.

So I guess it's a bug?

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the warning with the provided nanobus loop and inspect the emit path containing the shown nanotiming code. Trace how performance entries are created and verify the completed change no longer leaves entries accumulating during repeated emits or triggers the perf_hooks warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.