Skip to content

fix: avoid cpu spinloop#1

Merged
thegecko merged 1 commit into
node-usb:mainfrom
Julusian:fix/cpu-spinloop
May 1, 2026
Merged

fix: avoid cpu spinloop#1
thegecko merged 1 commit into
node-usb:mainfrom
Julusian:fix/cpu-spinloop

Conversation

@Julusian
Copy link
Copy Markdown
Contributor

Giving it a try, I am seeing some very high cpu usage. This is on linux x64, I havent checked other platforms.
Simply importing the library causes node to use two whole cpu cores.

Adding a connect listener usb.addEventListener('connect', (e) => console.log(e)) drops that to one core being maxed out.

These numbers are from using REPL:

Welcome to Node.js v22.22.2.
Type ".help" for more information.
> const usb =require('usb')
undefined
> usb.usb.addEventListener('connect', (e) => console.log(e))
undefined
> 

I havent touched rust in a while, and havent used tokio before so is largely a 3rd revision from claude. Seems to work when adding and removing listeners for me

@thegecko
Copy link
Copy Markdown
Member

thegecko commented May 1, 2026

@Julusian Thanks so much for this (first!) PR!

I'm also a rust n00b, so will check this out :)

@thegecko thegecko merged commit d228c55 into node-usb:main May 1, 2026
11 checks passed
@thegecko
Copy link
Copy Markdown
Member

thegecko commented May 1, 2026

All tests pass, thanks @Julusian !

@Julusian
Copy link
Copy Markdown
Contributor Author

Julusian commented May 4, 2026

Any chance of a new alpha build to be published with this?

@thegecko
Copy link
Copy Markdown
Member

thegecko commented May 4, 2026

On it...

@thegecko
Copy link
Copy Markdown
Member

thegecko commented May 4, 2026

usb@3.0.0-alpha.6 or usb@next

@Julusian
Copy link
Copy Markdown
Contributor Author

Julusian commented May 4, 2026

Thank you! the fans in my laptop can relax now 😆

and my testing deployment is a lot calmer too
image

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.

2 participants