Skip to content
All library documents

Using JavaScript Threads for Concurrent Strategy Tasks

Article FMZ digest · Author: 发明者量化-小小梦

Summary

This document explains how FMZ’s JavaScript strategies can run custom functions in parallel. It describes creating worker threads, passing arguments, joining a thread to obtain its return value and elapsed time, and forcibly terminating a worker. It also covers messaging between threads, including communication with the main thread, and storing and retrieving shared thread data. Examples include running independent HTTP requests concurrently and calculating Fibonacci numbers in JavaScript and WebAssembly.

The document compares concurrent execution of the same recursive Fibonacci workload and reports that WebAssembly finished sooner in the shown run. That result is a single platform-specific example, not a general benchmark: the document gives no repeated trials or broader performance analysis. It also states that JavaScript multithreading is available for live bots but was not supported in backtesting at the time described. The material is useful for understanding strategy engineering and concurrent workloads, rather than trading signals or performance of a trading strategy.

Key ideas

  • FMZ JavaScript threads can run custom functions concurrently and receive arguments.
  • Joining a thread waits for completion and provides its return value and execution details.
  • Threads can exchange messages with each other and with the main thread, whose ID is zero.
  • Thread-local key-value data can be accessed by another thread while the worker remains available.
  • A single Fibonacci comparison favored WebAssembly, but it does not establish a general speed advantage.
  • The document says JavaScript multithreading was unavailable in backtests at the time.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.