React Native Workers 为 React Native 提供基于独立 Hermes 运行时的真正多线程能力,采用类似 Web Worker 的 API,支持结构化克隆、原生模块访问、共享内存和类型化 RPC。

Stars

80

7 天增长

暂无数据

Fork 数

0

开放 Issue

0

开源协议

MIT

最近更新

2026-07-27

AI 仓库情报摘要
FR-AI / ANALYSIS

为什么值得关注

它解决了 React Native 长期存在的单 JS 线程阻塞问题,通过真正的多线程、原生模块支持、共享内存原语和极小的包体积实现性能优化。

适合谁使用

  • 需要处理 CPU 密集型任务的 React Native 开发者
  • 需要后台数据处理或并行计算的开发者
  • 使用原生模块且希望将工作从 UI 线程卸载的团队
  • 在 New Architecture 下优化 React Native 性能的工程师

典型使用场景

  • 将繁重的图像滤镜或视频处理卸载到后台线程
  • 在不卡顿 UI 的情况下运行实时传感器数据解析或模拟循环
  • 并行执行加密或数据压缩任务
  • 实现后台网络请求或数据库操作服务

项目优势

  • 每个 Worker 拥有独立的 Hermes 运行时、堆和事件循环
  • Worker 内部可完全访问原生模块(TurboModules、传统模块、Nitro)
  • 提供共享存储、共享值和共享缓冲区等共享内存原语,实现低延迟数据交换
  • 通过 Metro 垫片和树摇优化,Worker 包体积仅约 150 KB(常规 1.4 MB)

使用前须知

  • 需要 React Native 0.81.4+ 并启用 New Architecture 和 Hermes
  • 结构化克隆暂不支持 Map、Set、RegExp、Error 或 BigInt
  • 平台原生模块(Java/ObjC)需要每个 Worker 选择性开启,Android 需手动注册

README 快速开始

React Native Workers

Real threads for React Native. Web Worker–style API, backed by a separate Hermes runtime on its own thread — with structured-clone messaging, timers, shared memory, and full native-module access.

Documentation · Quick start · API reference · Examples


React Native runs all your JavaScript on a single JS thread, and drives UI updates from it. A long parse, a big image filter, or a tight simulation loop blocks that thread — so it can't dispatch updates and your UI stalls.

This library gives you a real one:

import { Worker } from '@ammarahmed/react-native-workers';

const worker = new Worker({
  inline: `self.onmessage = (e) => self.postMessage({ doubled: e.data * 2 });`,
});

worker.onmessage = (e) => console.log(e.data); // { doubled: 42 }
worker.postMessage(21);

It's a headless React Native: no UI, but the same JavaScript engine, the same timers and Promises, and the same native modules you already use.

Why it's different

A real threadIts own Hermes runtime with its own heap and event loop, not a time-slice of yours.
Native modules workTurboModules, legacy modules and Nitro modules all resolve inside a worker — react-native-mmkv, react-native-blob-util and friends work unmodified.
Shared memory, not just messagesA ladder from postMessage to lock-free shared cells and raw shared ArrayBuffers — pick the cost you want to pay.
Typed two-way RPCCall across the boundary like a local async function, in both directions, with one shared type.
Small bundlesWorker bundles ship ~150 KB instead of ~1.4 MB, because the UI half of React Native never enters the graph.
DebuggableEvery worker is its own DevTools target — breakpoints, stepping, and console.log forwarded to the host with a [Worker:name] tag.

Install

npm install @ammarahmed/react-native-workers

Requires the New Architecture with Hermes (RN 0.81.4+, developed against 0.86).

项目描述

Real threads for React Native. Web Worker–style API, backed by a separate Hermes runtime on its own thread — with structured-clone messaging, timers, shared memory, and full native-module access.

相关仓库与替代方案

根据分类、Topic 和编程语言匹配的相似项目。

makecindy
精选
makecindy GitHub avatar

cindy

Cindy is an open-source AI agent that runs locally on your machine, integrates multiple AI harnesses and models, and provides memory, skills, and automation to perform real work in your projects and apps.

AI 与机器学习大语言模型
958
TanStack
精选
TanStack GitHub avatar

router

TanStack Router is a type-safe, data-driven React router with built-in caching, prefetching, and nested layouts, while TanStack Start extends it into a full-stack SSR framework.

Web 开发前端框架
14,861
mereyabdenbekuly-ctrl
精选
mereyabdenbekuly-ctrl GitHub avatar

clodex-ide

Clodex is an open-source, local-first agentic IDE that combines persistent AI tasks, code, terminal, browser, Git, models, memory, and governed execution in one Electron workspace, currently in technical preview.

AI 与机器学习AI 智能体
859