Skip to content

Enhance worker thread performance and add SocketWorker class#11

Merged
jsilvanus merged 4 commits into
mainfrom
performance
Apr 14, 2026
Merged

Enhance worker thread performance and add SocketWorker class#11
jsilvanus merged 4 commits into
mainfrom
performance

Conversation

@jsilvanus
Copy link
Copy Markdown
Owner

This pull request introduces a new benchmarking suite for the worker pool and makes several improvements to worker communication, task queue efficiency, and embedding result handling. The key changes include adding micro-benchmarks for threads and processes, improving how embedding results are transferred and reshaped, and optimizing the pending task queue for better performance under load.

Benchmarking and Testing:

  • Added a new micro-benchmark script bench/micro-bench.js to compare thread and process worker pool performance, along with mock worker scripts for both process and thread modes. [1] [2] [3]

Worker Communication and Embedding Handling:

  • Enhanced the thread worker script to transfer embedding results as Float32Array buffers for zero-copy efficiency, including shape metadata for proper reconstruction.
  • Updated the worker pool to automatically reshape received embedding buffers (with shape info) back into number[][] arrays before resolving tasks, ensuring a consistent public API regardless of worker implementation.

Performance and Robustness Improvements:

  • Replaced the pending task array in WorkerPool with a custom FIFOQueue class to avoid performance issues with large queues and frequent Array.shift() calls. [1] [2] [3] [4]

New Worker Implementation:

  • Added a new SocketWorker class in src/socket-worker.js to support connecting to a socket-based model server using an NDJSON protocol, exposing an EventEmitter interface for compatibility with the pool.

@jsilvanus jsilvanus merged commit c68056a into main Apr 14, 2026
3 checks passed
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.

1 participant