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

Requiring this package on node uses 2 cpus #80

Open
rektide opened this issue Mar 28, 2018 · 11 comments
Open

Requiring this package on node uses 2 cpus #80

rektide opened this issue Mar 28, 2018 · 11 comments

Comments

@rektide
Copy link

rektide commented Mar 28, 2018

Hello. If I require('web-midi-api-shim'); navigator.requestMIDIAccess() from Node.js (say a repl, or small script) my Node process starts using two CPUs at >90%. Context-switches go from ~500/s to 36k/s.

This makes the library unsuitable for use on a laptop or battery powered system, and I am unsure but somewhat under the impression that it degrades my other web browsing activity on this computer.

@rektide
Copy link
Author

rektide commented Mar 28, 2018

I pulled some power consumption numbers from powertop and dstat, going from a fresh startup, to plugging in the Korg NanoKontrol2 I use, to running midisnoop listening via alsa while i tap ~2 buttons/s, to turning that off & starting web-midi-api-shim, running requetMIDIAccess() & nothing else, & again tapping ~2 buttons/s.

Stage Power (W) User cpu sys cpu Wakeups Context Switches
Idle 3.55 0% 0% 40 28
Device attached 4.31 0% 0% 55 50
midisnoop 4.55 5% 0% 415 340
web-midi-api-shim 10.4 21% 7% 560 36,000

@rektide
Copy link
Author

rektide commented Mar 28, 2018

I haven't tried using it in any real capacity what-so-ever, but https://github.com/abudaan/WebMIDIAPIShim/tree/upgrade-2018 branch shows very tame cpu usage. I'll see about reproducing above conditions to test how much better, but it looks really close to midisnoop. But I haven't done any real work with that branch yet!

@abudaan - can you report in on the status of that branch? what are the major work areas remaining? anything I can assist with?

@jazz-soft
Copy link
Contributor

Is that issue from WebMIDIAPIShim or from the underlying https://www.npmjs.com/package/jazz-midi ?

@rektide
Copy link
Author

rektide commented Mar 28, 2018

@jazz-soft I'm not super sure how to test. I imported jazz-midi in a repl, and ran midi.MidiOutOpen(0) and midi.MidiInOpen(0) and my cpu consumption & power is fine. There doesn't appear to be any kind of event-based api in jazz-midi to, for example, see button presses. That implies I'd have to write some kind of loop to sample the device?

@jazz-soft
Copy link
Contributor

You can set the callback function in jazz-midi: http://jazz-soft.net/doc/Jazz-Plugin/MidiInOpen.html
But it may be more convenient to use via the JZZ library: https://github.com/jazz-soft/JZZ

@rektide
Copy link
Author

rektide commented Mar 28, 2018

@jazz-soft In @abudaan's update-2018 branch, he's started switching WebMIDIAPIShim to use jzz. :) I'm just starting to test whether the basic functionality I need works on that branch.

@jazz-soft
Copy link
Contributor

I believe that was an experimental branch.

@abudaan
Copy link
Contributor

abudaan commented Mar 28, 2018

@jazz-soft @rektide Yes, Sema is right, update-2018 is still wip; currently it is a quick-and-dirty implementation of the latest Jazz plugin but it has all functionality so you can use it.

I will start working on this branch again early April and it will be backwards compatible so you should be able to update the WebMIDIAPIShim by then without breaking your project's code.

@jazz-soft
Copy link
Contributor

@abudaan FYI: I'm planning to make JZZ expose Web MIDI API in the next release. If you are interested, we can discuss it by email.

rektide added a commit to rektide/web-midi-nanokontrol that referenced this issue Apr 5, 2018
This entire dependency is about to be deprecated by jzz's direct implementation
of web-midi ( cwilso/WebMIDIAPIShim#80 ) but I just want
the magic to happen. Also this is using my fork of web-midi-api-shim. :p
rektide added a commit to rektide/web-midi-nanokontrol that referenced this issue Apr 5, 2018
This entire dependency is about to be deprecated by jzz's direct implementation
of web-midi ( cwilso/WebMIDIAPIShim#80 ) but I just want
the magic to happen. Also this is using my fork of web-midi-api-shim. :p
rektide added a commit to rektide/web-midi-nanokontrol that referenced this issue Apr 5, 2018
This entire dependency is about to be deprecated by jzz's direct implementation
of web-midi ( cwilso/WebMIDIAPIShim#80 ) but I just want
the magic to happen. Also this is using my fork of web-midi-api-shim. :p
@jazz-soft
Copy link
Contributor

@rektide & @abudaan, please have a look at https://github.com/jazz-soft/JZZ - it now enables Web MIDI API

@abudaan
Copy link
Contributor

abudaan commented Apr 21, 2018

Great work! I have replaced the WebMIDIAPIShim in both heartbeatjs and qambi and it works like a charm! I think we can now deprecate the WebMIDIAPIShim?

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

3 participants