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

Remove Add Event Listeners? #316

Open
fadi-george opened this issue Jul 3, 2024 · 1 comment
Open

Remove Add Event Listeners? #316

fadi-george opened this issue Jul 3, 2024 · 1 comment

Comments

@fadi-george
Copy link

Hello, I was looking to using this package in an effort to replace Dexie with a smaller package. When I profiling idb against Dexie and other options, I noticed that it adds way more event listeners than expected.

I made a simple setup here: https://github.com/fadi-george/idb-test

I noticed that with idb, I see a lot of listeners being added.
idb-1

And it can be up to 2x the number of listeners compared to Dexie.
dexie-2

Basic IndexDB for comparison:
basic-1

Which brings me to my point where I copied over the idb src files and changed the event listeners to event handlers. Things like:

request.addEventListener('upgradeneeded', (event) => { ...

being changed into

request.onupgradeneeded = (event) => { ...

And then saw an obvious reduction in the listener count.
idb-custom-1

So maybe it would be good to switch all the event listeners to event handlers.

@jakearchibald
Copy link
Owner

Are you seeing some kind of leak here? The 'upgradeneeded' event in particular is only added once per database connection, so I don't see how there'd be any kind of real world difference between a listener and a handler here.

I use listeners rather than handlers so they're not overwritten if people get the unwrapped values and override the handlers.

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

No branches or pull requests

2 participants