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
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
100
42 best practices for Symfony, a decade later
tucksaun
1
180
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
390
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
370
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
Zoneless Testing
rainerhahnekamp
0
120
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
250
Jakarta EE meets AI
ivargrimstad
0
240
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
4
490
命名をリントする
chiroruxx
1
410
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Docker and Python
trallard
42
3.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
The Cost Of JavaScript in 2023
addyosmani
45
7k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Fireside Chat
paigeccino
34
3.1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
450
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
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