Skip to content

Implement Asynchronous MIDI Processing for Improved Scalability#4647

Closed
pushpitkamboj wants to merge 2 commits intosugarlabs:masterfrom
pushpitkamboj:midi-optimized
Closed

Implement Asynchronous MIDI Processing for Improved Scalability#4647
pushpitkamboj wants to merge 2 commits intosugarlabs:masterfrom
pushpitkamboj:midi-optimized

Conversation

@pushpitkamboj
Copy link
Copy Markdown

Fix : #4626

Core Idea

The primary goal is to modify the transcribeMidi function to prevent browser unresponsiveness with large MIDI files by implementing asynchronous chunking and memory optimizations.

Async Processing

The core refactoring lies in processing the MIDI data in smaller chunks asynchronously to prevent the browser from freezing. The processChunk function, processes notes in small chunks and yield back to the main thread using setTimeout or async/await, which prevents locking up the browser during long operations.

Environment:

Operating System: Windows
Browser: Chrome

Checklist

  • I have read and followed the project's code of conduct.
  • I have searched for similar issues before creating this one.
  • I have provided all the necessary information to understand and reproduce the issue.
  • I am willing to contribute to the resolution of this issue.

@github-actions
Copy link
Copy Markdown
Contributor

❌ Some Jest tests failed. Please check the logs and fix the issues before merging.

Failed Tests:

ToneBlocks.test.js
midi.test.js

@omsuneri
Copy link
Copy Markdown
Member

@pushpitkamboj please provide a video of importing midi blocks more than 800 does that problem solved or not ???
I m afk better if you upload a video for reference

@github-actions
Copy link
Copy Markdown
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@pushpitkamboj
Copy link
Copy Markdown
Author

Screen.Recording.2025-04-25.215933.mp4

I tried my best to optimize but don't know if we can optimize it more with the existing processing on browser. Need to think of another alternatives to reduce the buffer for better UX.

@walterbender
Copy link
Copy Markdown
Member

Your changes broke the unit test.
Even with your changes it seems slow and unresponsive. Maybe it is worthwhile adding a warning message: "WARNING: Loading large MIDI files will be slow on some browsers."

@omsuneri
Copy link
Copy Markdown
Member

@walterbender it's a good idea to give a text msg instead of refactoring midi importer
I ll close that issue

@pushpitkamboj
Copy link
Copy Markdown
Author

I get it, maybe adding a warning message is better idea.

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.

Efficient working of midi import >400 blocks

3 participants