Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
TurboModuleを用いたJSスレッドの負担軽減と Follyを用いたMainスレッドのマ...
Search
TaichiAkimoto
October 02, 2021
Programming
2
310
TurboModuleを用いたJSスレッドの負担軽減と Follyを用いたMainスレッドのマルチスレッド化
株式会社BluAgeの業務内容とReact Nativeの最新技術への取り組みの紹介スライドです。
TaichiAkimoto
October 02, 2021
Tweet
Share
Other Decks in Programming
See All in Programming
php-conference-japan-2024
tasuku43
0
410
テストコード書いてみませんか?
onopon
2
290
オニオンアーキテクチャを使って、 Unityと.NETでコードを共有する
soi013
0
350
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
1.3k
Fibonacci Function Gallery - Part 2
philipschwarz
PRO
0
200
ISUCON14感想戦で85万点まで頑張ってみた
ponyo877
1
190
PHPカンファレンス 2024|共創を加速するための若手の技術挑戦
weddingpark
0
110
技術的負債と向き合うカイゼン活動を1年続けて分かった "持続可能" なプロダクト開発
yuichiro_serita
0
250
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
330
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
8
1.8k
HTML/CSS超絶浅い説明
yuki0329
0
160
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
9
2.3k
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Fireside Chat
paigeccino
34
3.1k
RailsConf 2023
tenderlove
29
960
Practical Orchestrator
shlominoach
186
10k
Statistics for Hackers
jakevdp
797
220k
What's in a price? How to price your products and services
michaelherold
244
12k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.2k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
490
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Adopting Sorbet at Scale
ufuk
74
9.1k
Transcript
TurboModuleΛ༻͍ͨJSεϨουͷ ෛ୲ܰݮͱ FollyΛ༻͍ͨMainεϨουͷϚϧν εϨουԽ React Native Matsuri 2021 Taichi Akimoto
2021/10/02
ࣗݾհ ໊લ: ѰݩଠҰ (͖͋ͱ͍ͨͪ) ৬ۀ: ϑϩϯτΤϯυΤϯδχΞ ※React Native͕ϝΠϯ ܦྺ: 20184݄ʹגࣜձࣾBluAgeΛۀ
͓෦୳͠ΞϓϦͷʮΧφϦʔʯͷ։ൃɾӡ༻ @AkimotoTaichi
Ұؾ௨؏ͨ͠σδλϧϓϥοτϑΥʔϜΛߏங ΧφϦʔಠ݅ ΞϓϦʮΧφϦʔʯΛల։ ࣗࣾհ/ૹ٬ SaaSఏڙʢސ٬ཧ[CRM]ʣ ିཧۀΛ࣮ࢪ SaaSఏڙ Ϣʔβʔ հ ݅ݩ/ཧ
ିചങͷ྆ํͰෳϓϩμΫτΛఏڙ͠ɺՃՁΛੵΈॏͶΔ ͦΕΒΛ࿈ܞ͢Δ͜ͱʹΑͬͯɺߏతͳ༏ҐੑʢMOATʣΛߏங
TurboModuleͱ
TurboModuleͱ
TurboModuleͱ
JSIʹΑΔସϥΠϒϥϦ Crypto DataBase Camera https://github.com/mrousavy/react-native-vision-camera
CodeGenʹΑΔTurboModuleͷੜ
݁ߏΒΕ͍ͯͳ͍͕TurboModuleͷ࡞؆୯
TurboModuleͷ࡞3εςοϓ Console࣮ߦ Schema NativeͷInterfaceੜ
Schema࡞ e.g. Sqlite import { TurboModule, TurboModuleRegistry } from "react-native-tscodegen-types";
type KeyValue = { key: string; text: string; }; export interface Spec extends TurboModule { getDraft: (key: string) => Promise<string>; updateDraft: (draft: KeyValue) => Promise<boolean>; ... } export default TurboModuleRegistry.getEnforcing<Spec>("Poc") as Spec;
TurboModuleग़ྗ e.g. Sqlite namespace facebook { namespace react { static
jsi::Value __hostFunction_PocModuleSchemaCxxSpecJSI_getDraft( jsi::Runtime &rt, TurboModule &turboModule, const jsi::Vaue *args, size_t count) { return static_cast<PocModuleSchemaCxxSpecJSI *>(&turboModule) ->getData(rt, args[0].getString(rt)); }
࣮ e.g. Sqlite namespace poc { using namespace facebook::react; jsi::Value
PocModule::getDraft(jsi::Runtime &rt, const jsi::String &key) { std::string keyStr = key.utf8(rt); … draftStr = DatabaseManager::getQueryExecutor().getDraft(keyStr); … this->jsInvoker_->invokeAsync([=, &innerRt]() { if (error.size()) { promise->reject(error); return; } jsi::String draft = jsi::String::createFromUtf8(innerRt, draftStr); promise->resolve(std::move(draft)); }); }; ...
TurboModuleʹΑͬͯJSϨΠϠʔͷෛ୲͕ܰݮ͞Εͨʂ
FollyʹΑΔMainεϨουͷϚϧνεϨουԽ Main thread Crypto thread DB thread Job 1 Job
2 Job 3 Job 4 Job 5 Job 6
NativeϨΠϠʔͷॏ͍ॲཧΛεϨουͰඇಉظʹॲཧ namespace poc { namespace jsi = facebook::jsi; class PocModule
: public facebook::react::PocModuleSchemaCxxSpecJSI { std::unique_ptr<WorkerThread> databaseThread; std::unique_ptr<WorkerThread> cryptoThread;
ThreadSafeͳMPMCQueueͷར༻ WorkerThread::WorkerThread(const std::string name) : tasks(folly::MPMCQueue<std::unique_ptr<taskType>>(100)), name(name) { auto job
= [this]() { while (true) { std::unique_ptr<taskType> lastTask; this->tasks.blockingRead(lastTask); if (lastTask == nullptr) { break; } (*lastTask)(); } }; this->thread = std::make_unique<std::thread>(job); }
MultiThreadingΛར༻͍ͯ͠ΔϥΠϒϥϦ ɾreact-native-multithreading https://github.com/mrousavy/react-native-multithreading reanimatedͷworkletΛར༻ͯ͠multithreadԽΛ࣮ ɾcomm https://github.com/CommE2E/comm/tree/master/native follyΛར༻ͯ͠multithreadԽΛ࣮
React NativeNativeΛͰ্ճΕΔ!? MultiThreading TurboModule
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ ෆಈ࢈ۀքςοΫʹ ڵຯ͕͋Δํ RNͷ࠷৽ಈʹ ڵຯ͕͋Δํ Meety: https://meety.net/matches/TtNbnknTpdPJ