1. ํ์ ์ฌ์ ์๊ฑด & ์์คํ ์๊ตฌ์ฌ์ (Prerequisites & System Requirements)
Lynx๋ ๊ธ๋ก๋ฒ ์ํผ ํ๋ซํผ ํฑํก(TikTok)๊ณผ ๋์ฐ์ธ(Douyin)์ ๊ฐ๋ฐํ **๋ฐ์ดํธ๋์ค(ByteDance)**๊ฐ ์ ์ธ๊ณ ์์ญ์ต ์ฌ์ฉ์ ํ๊ฒฝ์์ ๊ฒ์ฆํ ํ ์คํ์์ค๋ก ์ ๊ฒฉ ๊ณต๊ฐํ ์ฐจ์ธ๋ ๊ณ ์ฑ๋ฅ ๋ค์ดํฐ๋ธ ํฌ๋ก์ค ํ๋ซํผ ํ๋ ์์ํฌ์ ๋๋ค.
๊ธฐ์กด ๋ชจ๋ฐ์ผ ํฌ๋ก์ค ํ๋ซํผ ๊ธฐ์ (React Native, Flutter, WebView/Capacitor)์ ๊ณ ์ง์ ์ธ ํ๊ณ์๋ โ์ด๊ธฐ ๋ก๋ฉ ๋๋ ์ด(First Paint Lag)โ, โ๋ณต์กํ ์๋ฐ์คํฌ๋ฆฝํธ-๋ค์ดํฐ๋ธ ๋ธ๋ฆฟ์ง ์ค๋ฒํค๋๋ก ์ธํ ์คํฌ๋กค ๋ฒ๋ฒ ์โ, **โ์น ํ์ค CSS ๋ฏธ์ง์์ผ๋ก ์ธํ ์คํ์ผ๋ง ํ์ต ๋น์ฉโ**์ ๊ทผ๋ณธ์ ์ผ๋ก ํ์ ํ์ต๋๋ค.
Lynx๋ **์์ ํ ๋์ผ ์ค๋ ๋(Dual-Thread Engine: Main UI Thread โท Background Runtime Thread)**์ C++ ๊ธฐ๋ฐ์ ๋ค์ดํฐ๋ธ ๋ ๋๋ง ์ฝ์ด, ๊ทธ๋ฆฌ๊ณ Rspack ๊ธฐ๋ฐ ์ด๊ณ ์ ๋ฒ๋ค๋ฌ์ธ Rspeedy๋ฅผ ์ฑํํ์ฌ ์น ๊ธฐ์ (React/Vue ์คํ์ผ JSX + ์น ํ์ค CSS)๋ก 120fps์ ๋ฌํ๋ ์คํคํ ๋ค์ดํฐ๋ธ ์ฌ์ฉ์ ๊ฒฝํ์ ์ ๊ณตํฉ๋๋ค.
๐ป ์์คํ ์ค์น ๋ฐ ์คํ ์๊ตฌ์ฌ์ (System Requirements)
| ํญ๋ชฉ | ์ต์ ์ฌ์ (Minimum) | ๊ถ์ฅ ์ฌ์ (Recommended) | ์ฐธ๊ณ ๋ฐ ๋น๊ณ |
|---|---|---|---|
| ์ด์์ฒด์ (OS) | macOS 13+ (Ventura/Sonoma/Sequoia), Windows 10/11, Linux (Ubuntu 22.04 LTS+) | macOS 14+ (Apple Silicon M2/M3/M4) | iOS ์๋ฎฌ๋ ์ดํฐ ๋ฐ ๋น๋๋ macOS ํ๊ฒฝ ํ์ (Windows/Linux๋ Android ์ง์) |
| CPU | 4 ์ฝ์ด ์ด์ (x86_64, ARM64) | 8 ์ฝ์ด ~ 10 ์ฝ์ด ์ด์ | C++ ๋ค์ดํฐ๋ธ ๋ฐํ์ ์ปดํ์ผ ๋ฐ Rspeedy ์ด๊ณ ์ HMR ๋ฒ๋ค๋ง |
| ๋ฉ๋ชจ๋ฆฌ (RAM) | 8 GB ์ด์ | 16 GB ~ 32 GB ์ด์ | Android Studio / Xcode + ์๋ฎฌ๋ ์ดํฐ + Node.js ๋ฐํ์ ๋์ ๊ตฌ๋ |
| ๋์คํฌ (Storage) | 20 GB ์ด์์ ์ฌ์ ๊ณต๊ฐ | 50 GB ~ 100 GB ์ด์์ ๊ณ ์ NVMe SSD | Android SDK, Xcode ๋น๋ ์บ์, Gradle ๋ฐ CocoaPods ์์กด์ฑ ์ ์ฅ์ |
| ๋คํธ์ํฌ / ๋ฐํ์ | Node.js v18.0.0+ ๋๋ v20.0.0+ LTS, pnpm 9+ ๋๋ npm 10+ | Node.js v22 LTS, pnpm 9+, Android SDK (API 26+), Xcode 15+ | ์์๋ฐ์ด๋ ์ธํฐ๋ท (npm ๋ฐ CocoaPods/Maven ์ ์ฅ์ 443 ํฌํธ) |
[!IMPORTANT] ์ Lynx์ธ๊ฐ? (TikTok 10์ต ์ ์ ๊ฐ ๊ฒ์ฆํ 4๋ ํต์ฌ ํ์ )
- Dual-Thread UI & Background ๊ฒฉ๋ฆฌ ์ํคํ ์ฒ: ๋น์ฆ๋์ค ๋ก์ง(React ์ํ, ๋คํธ์ํฌ, JSON ํ์ฑ)์ ๋ฐฑ๊ทธ๋ผ์ด๋ ์ค๋ ๋์์ ๋์๊ฐ๋ฉฐ, ๋ฉ์ธ UI ์ค๋ ๋๋ ๋ ๋๋ง์๋ง ์ง์คํ๋ฏ๋ก ์ด๋ค ๋ฌด๊ฑฐ์ด ๊ณ์ฐ ์ค์๋ ์คํฌ๋กค์ด ์ ๋ ๋๊ธฐ์ง ์์ต๋๋ค.
- Main Thread Script (MTS / Worklet): ํ์น ํฌ ์ค, ๋๋๊ทธ ์ค์์ดํ ๋ฑ ์ ์ค์ฒ ์ฒ๋ฆฌ๋ฅผ ๋ฐฑ๊ทธ๋ผ์ด๋ ์ค๋ ๋๋ฅผ ๊ฑฐ์น์ง ์๊ณ UI ์ค๋ ๋์์ ์ง์ 0ms ์ง์ฐ์ผ๋ก ์คํํ์ฌ 120fps์ ๊ทน์ ๋ถ๋๋ฌ์์ ๊ตฌํํฉ๋๋ค.
- ์น ํ์ค CSS Flexbox & Grid ์๋ฒฝ ํธํ: React Native์ฒ๋ผ ์ ํ๋ ์ธ๋ผ์ธ ์คํ์ผ ๊ฐ์ฒด๋ฅผ ์ฐ์ง ์๊ณ , ํ์ค
.cssํ์ผ๊ณผ Flexbox,linear-gradient, CSS Keyframes ์ ๋๋ฉ์ด์ ์ ๊ทธ๋๋ก ์ฌ์ฉํ ์ ์์ต๋๋ค.- ์ด๊ฒฝ๋ ๋ฒ๋ค๋ฌ Rspeedy (Rust ๊ธฐ๋ฐ): ๊ธฐ์กด Metro ๋ฒ๋ค๋ฌ ๋๋น 10๋ฐฐ ์ด์ ๋น ๋ฅธ Rust Rspack ๊ธฐ๋ฐ์ผ๋ก ์์ฒ ๊ฐ ์ปดํฌ๋ํธ์ ํ๋ก์ ํธ๋ 1์ด ๋ง์ ๋น๋ ๋ฐ ํซ ๋ฆฌ๋ก๋(HMR)๋ฉ๋๋ค.
๐ฑ Lynx Explorer ํ๋ฆฌ๋ทฐ ์ฑ ์ค๋น
Lynx๋ ๊ฐ๋ฐ์์ฉ ๊ณต์ ๋ชจ๋ฐ์ผ ์๋๋ฐ์ค ์ฑ์ธ Lynx Explorer๋ฅผ ์ ๊ณตํฉ๋๋ค. ๋ณต์กํ Xcode/Android Studio ๋ค์ดํฐ๋ธ ๋น๋ ๊ณผ์ ์์ด, ์ค๋งํธํฐ์ด๋ ์๋ฎฌ๋ ์ดํฐ์ Lynx Explorer๋ฅผ ์ค์นํ๊ณ QR ์ฝ๋๋ง ์ค์บํ๋ฉด ์ฆ์ ์ค์๊ฐ HMR๋ก ๊ฐ๋ฐํ ์ ์์ต๋๋ค.
- Android: ๊ณต์ GitHub Releases์์
lynx-explorer.apk๋ค์ด๋ก๋ ๋ฐ ์ค์น (adb install lynx-explorer.apk) - iOS: Mac ํ๊ฒฝ์์ Xcode ์๋ฎฌ๋ ์ดํฐ ๋๋ TestFlight/์์ฒด ์๋ช ์ค์น
2. ์ง๊ด์ ์ธ ๋ฉํ ๋ชจ๋ธ (Dual-Thread Architecture & Mental Model)
Lynx๋ ์น ๋ธ๋ผ์ฐ์ ์ ๋จ์ผ ์ค๋ ๋ ๋ณ๋ชฉ๊ณผ ์ ํต์ ๋ชจ๋ฐ์ผ ํ์ด๋ธ๋ฆฌ๋ ์ฑ์ ๋๋ฆฐ ๋ธ๋ฆฟ์ง ๊ตฌ์กฐ๋ฅผ ๊ทน๋ณตํ๊ธฐ ์ํด ์์ง ์์ค์์ ์ค๋ ๋๋ฅผ 2๊ฐ๋ก ์๋ฒฝํ ๋ถ๋ฆฌํ์ต๋๋ค.
+---------------------------------------------------------------------------------------------------+
| Lynx Dual-Thread Engine Architecture |
+---------------------------------------------------------------------------------------------------+
| |
| [ 1. Main / UI Thread ] (120fps ๋ค์ดํฐ๋ธ ๋ ๋๋ง & ์ ์ค์ฒ ์ ๋ด ์ค๋ ๋) |
| - ์ ๋ ๋ฉ์ถ์ง ์๋ ๋ ๋ ๋ฃจํ (Non-blocking Smooth Scrolling) |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ |
| โ ๐จ Native UI Layer (Android Views / iOS UIViews) โ |
| โ - WebView DOM์ด ์๋ 100% ๋ค์ดํฐ๋ธ ์ปดํฌ๋ํธ ์ง์ ์์ฑ (<view>, <text>, <image>, <list>) โ |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค |
| โ ๐ C++ Native Layout Engine (Flexbox / Grid ๊ณ ์ ์ฐ์ฐ) โ |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค |
| โ โก Main Thread Script (MTS / Worklet) โ |
| โ - ํฐ์น, ๋๋๊ทธ, ์ค์์ดํ ์ ์ค์ฒ๋ฅผ UI ์ค๋ ๋์์ 0ms ์ง์ฐ์ผ๋ก ์ง์ ์ฒ๋ฆฌ (120fps ๋ณด์ฅ) โ |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฒโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ |
| โ |
| โก ๋น๋๊ธฐ Diff ํจ์น ์ ๋ฌ โ ์ด๋ฒคํธ ์ ๋ฌ (tap, scroll, etc.) |
| (UI ์ค๋ ๋ ๋ธ๋กํน ์ ๋ก!) โ |
| โ |
| [ 2. Background Runtime Thread ] (๋น์ฆ๋์ค ๋ก์ง & ๋ฆฌ์กํธ ์ํ ๊ด๋ฆฌ ์ ๋ด ์ค๋ ๋) |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ |
| โ ๐งฉ QuickJS / PrimJS / V8 JavaScript Engine โ |
| โ - React / Lynx UI ์ปดํฌ๋ํธ ์๋ช
์ฃผ๊ธฐ ๋ฐ ๋ ๋๋ง ๊ณ์ฐ โ |
| โ - ์ํ ๊ด๋ฆฌ (Zustand, Redux, React Hooks `useState`, `useEffect`) โ |
| โ - ๋น์ฆ๋์ค ๋ก์ง, ๋๊ท๋ชจ JSON ํ์ฑ, ๋คํธ์ํฌ REST API / WebSocket ํธ์ถ โ |
| โ - C++ ๊ฐ์ DOM Diff ์๊ณ ๋ฆฌ์ฆ์ ์ํํ์ฌ ์ต์ ๋ณ๊ฒฝ๋ถ๋ง UI ์ค๋ ๋๋ก ๋น๋๊ธฐ ์ ์ก โ |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ |
+---------------------------------------------------------------------------------------------------+
โ๏ธ Lynx vs React Native vs Flutter vs Capacitor ๊ธฐ์ ๋น๊ต
| ๋น๊ต ํญ๋ชฉ | Lynx (ByteDance) | React Native (New Arch) | Flutter | Capacitor / Ionic |
|---|---|---|---|---|
| ๋ ๋๋ง ์์ง | ๋ค์ดํฐ๋ธ View (C++ ์ฝ์ด ์ง์ ์ ์ด) | ๋ค์ดํฐ๋ธ View (Fabric ๋ ๋๋ฌ) | Skia / Impeller ์์ฒด ๊ทธ๋ํฝ ๋ ๋๋ง | ๋ชจ๋ฐ์ผ ๋ธ๋ผ์ฐ์ WebView DOM |
| ์ค๋ ๋ ์ํคํ ์ฒ | Dual-Thread (Main UI + Background) | JS Thread + UI Thread | UI Thread + Platform Thread | ์น๋ทฐ ๋จ์ผ ์ค๋ ๋ |
| ์ ์ค์ฒ ๋ฌด์ง์ฐ | MTS (Main Thread Script) ๋ด์ฅ | Reanimated ๋ณ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ์ | Dart ๋จ์ผ ์ค๋ ๋ ๋ด ์ฒ๋ฆฌ | ๋ถ๊ฐ๋ฅ (์น ์คํฌ๋กค ์ด๋ฒคํธ ์ง์ฐ) |
| ์คํ์ผ๋ง | ์น ํ์ค CSS (Flexbox, ์ ๋๋ฉ์ด์ ) | ์ปค์คํ StyleSheet ๊ฐ์ฒด (์ ํ์ ) | Dart ์์ ฏ ํธ๋ฆฌ ์คํ์ผ๋ง | ์น ํ์ค CSS |
| ๋ฒ๋ค๋ฌ | Rspeedy (Rust Rspack ๊ธฐ๋ฐ, ์ด๊ณ ์) | Metro ๋ฒ๋ค๋ฌ | Dart ์์ฒด AOT ์ปดํ์ผ๋ฌ | Vite / Webpack |
| ์ฒซ ํ๋ฉด ํ์ (FP) | ํ ํ๋ฆฟ ์ฌ์ ๋์ฝ๋ฉ์ผ๋ก ๋ค์ดํฐ๋ธ๊ธ FP | JS ๋ฒ๋ค ํ์ฑ ์ง์ฐ ์กด์ฌ | ์์ง ์ด๊ธฐํ ์๊ฐ ์์ | ์น๋ทฐ ์ด๊ธฐํ ์ค๋ฒํค๋ ํผ |
3. [์ด๋ณด์ 1๋จ๊ณ] ํฌ๋ก์๋: Lynx CLI ์ค์น์ ์ฒซ ์ปดํฌ๋ํธ ๋ ๋๋ง
๐ 1. ์ ๊ท Lynx ํ๋ก์ ํธ ์์ฑ (create-lynx)
๊ณต์ ์ค์บํด๋ฉ ๋๊ตฌ๋ฅผ ์ฌ์ฉํ์ฌ TypeScript + React ํ ํ๋ฆฟ์ Lynx ํ๋ก์ ํธ๋ฅผ ์์ฑํฉ๋๋ค.
# 1. pnpm์ ํตํ Lynx ์ต์ ํ๋ก์ ํธ ์์ฑ
pnpm create lynx@latest my-lynx-app
# ํ
ํ๋ฆฟ ์ ํ: React + TypeScript ์ ํ
# ๋๋ ํ ๋ฆฌ ์ด๋ ๋ฐ ์์กด์ฑ ์ค์น
cd my-lynx-app
pnpm install
# 2. ๋ก์ปฌ ๊ฐ๋ฐ ์๋ฒ(Rspeedy) ์คํ
pnpm dev
์ฝ์ ์ถ๋ ฅ ์์ (pnpm dev):
Rspeedy v0.7.0 dev server running at:
โ Local: http://localhost:3000/
โ Network: http://192.168.1.50:3000/
๐ฑ Scan QR code with Lynx Explorer to preview:
[โโโโโโโโโโโโโโโโโโโโโโโโโ]
ํฐ๋ฏธ๋์ ์ถ๋ ฅ๋ QR ์ฝ๋๋ฅผ ๋ชจ๋ฐ์ผ ๊ธฐ๊ธฐ์ Lynx Explorer ์ฑ์ผ๋ก ์ค์บํ๋ฉด 1์ด ๋ง์ ์ค๋งํธํฐ ํ๋ฉด์ ์ฑ์ด ๋ก๋๋ฉ๋๋ค!
๐ ํ์ค ํ๋ก์ ํธ ๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ
my-lynx-app/
โโโ src/
โ โโโ App.tsx # ๋ฉ์ธ ๋ฃจํธ ํ๋ฉด ์ปดํฌ๋ํธ
โ โโโ App.css # ์น ํ์ค CSS ์คํ์ผ์ํธ
โ โโโ index.tsx # Lynx ์ํธ๋ฆฌํฌ์ธํธ (root.render)
โโโ lynx.config.ts # Rspeedy ๋ฒ๋ค๋ฌ ๋ฐ Lynx ์์ง ์ค์ ํ์ผ
โโโ tsconfig.json # TypeScript ์ปดํ์ผ๋ฌ ์ค์
โโโ package.json # ์์กด์ฑ (@lynx-js/react, @lynx-js/rspeedy)
๐ 2. ์ฒซ ์ปดํฌ๋ํธ ์์ฑ (src/App.tsx & src/App.css)
์น ๊ฐ๋ฐ์์๊ฒ ์ต์ํ React Hooks์ ์น ํ์ค CSS๋ก ์นด์ดํฐ ์ฑ์ ์์ฑํฉ๋๋ค.
// src/App.tsx
import { useState } from '@lynx-js/react';
import './App.css';
export function App() {
const [count, setCount] = useState<number>(0);
const handleIncrement = () => {
setCount((prev) => prev + 1);
};
const handleReset = () => {
setCount(0);
};
return (
<view className="container">
{/* ํค๋ ํ์ดํ: ๋ชจ๋ ํ
์คํธ๋ ๋ฐ๋์ <text> ํ๊ทธ๋ก ๊ฐ์ธ์ผ ํจ */}
<view className="header-box">
<text className="title">๐ Hello, Lynx World!</text>
<text className="subtitle">ByteDance 120fps Dual-Thread Native</text>
</view>
{/* ์นด์ดํฐ ๋์คํ๋ ์ด ์นด๋ */}
<view className="card">
<text className="label">ํ์ฌ ์นด์ดํธ ์์น</text>
<text className="counter-value">{count}</text>
<view className="button-group">
<view className="btn btn-primary" bindtap={handleIncrement}>
<text className="btn-text">+1 ์ฆ๊ฐํ๊ธฐ</text>
</view>
<view className="btn btn-secondary" bindtap={handleReset}>
<text className="btn-text">์ด๊ธฐํ</text>
</view>
</view>
</view>
</view>
);
}
/* src/App.css */
/* ๐ก ์น ํ์ค CSS Flexbox ๋ฌธ๋ฒ ๊ทธ๋๋ก ์์ฑ! */
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
background-color: #0f172a;
padding: 24px;
}
.header-box {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 32px;
}
.title {
font-size: 28px;
font-weight: 800;
color: #38bdf8;
margin-bottom: 8px;
}
.subtitle {
font-size: 14px;
color: #94a3b8;
}
.card {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
max-width: 340px;
background-color: #1e293b;
border-radius: 16px;
padding: 24px;
border: 1px solid #334155;
}
.label {
font-size: 14px;
color: #cbd5e1;
margin-bottom: 8px;
}
.counter-value {
font-size: 48px;
font-weight: 900;
color: #f8fafc;
margin-bottom: 24px;
}
.button-group {
display: flex;
flex-direction: row;
gap: 12px;
width: 100%;
}
.btn {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
padding: 12px 16px;
border-radius: 8px;
}
.btn-primary {
background-color: #0284c7;
}
.btn-secondary {
background-color: #475569;
}
.btn-text {
color: #ffffff;
font-size: 15px;
font-weight: 600;
}
4. [2๋จ๊ณ] ํต์ฌ ๊ธฐ๋ฅ 1: Lynx ๋นํธ์ธ UI ์ปดํฌ๋ํธ ๊ท๊ฒฉ
Lynx๋ HTML ํ๊ทธ(div, span, img) ๋์ ๋ค์ดํฐ๋ธ ๋ทฐ์ ์ง์ ๋งคํ๋๋ 5๋ ํต์ฌ ์ปดํฌ๋ํธ๋ฅผ ์ ๊ณตํฉ๋๋ค.
| ์ปดํฌ๋ํธ ํ๊ทธ | ๋์ ํ๋ซํผ ๋ค์ดํฐ๋ธ ๋ทฐ | ์ฃผ์ ์ฉ๋ ๋ฐ ํต์ฌ ํน์ง |
|---|---|---|
<view> | Android ViewGroup / iOS UIView | Flexbox ๋ฐ Grid ๋ ์ด์์์ ๊ตฌ์ฑํ๋ ๊ธฐ๋ณธ ์ปจํ ์ด๋ |
<text> | Android TextView / iOS UILabel | ํ
์คํธ ์ถ๋ ฅ ์ปดํฌ๋ํธ (ํ
์คํธ๋ ๋ฐ๋์ <text> ๋ด๋ถ์ ์์นํด์ผ ๋ ๋๋ง๋จ) |
<image> | Android ImageView / iOS UIImageView | ๊ณ ์ฑ๋ฅ ์ด๋ฏธ์ง ๋ก๋ฉ (src, mode="aspectFill", placeholder ์ง์) |
<scroll-view> | Android ScrollView / iOS UIScrollView | ์ผ๋ฐ ์คํฌ๋กค ๋ทฐ (scroll-orientation="vertical" ๋๋ "horizontal") |
<list> | Android RecyclerView / iOS UICollectionView | ๋๊ท๋ชจ ๋ชฉ๋ก ๊ฐ์ํ(Virtualization) ์ปดํฌ๋ํธ (TikTok ํผ๋ ์ ์ฉ ๊ณ ์ ์ฌํ์ฉ) |
5. [2๋จ๊ณ] ํต์ฌ ๊ธฐ๋ฅ 2: 120fps ๋ฌด์ง์ฐ ์ ์ค์ฒ๋ฅผ ์ํ Main Thread Script (MTS / Worklet)
์ผ๋ฐ์ ์ธ ๋ชจ๋ฐ์ผ ํ๋ ์์ํฌ๋ ์ฌ์ฉ์๊ฐ ํ๋ฉด์ ํฐ์นํ ๋ ์ด๋ฒคํธ๊ฐ **[UI Thread โ JS Thread โ ์ํ ์ฐ์ฐ โ UI Thread]**๋ก ์ค๋ ๋๋ฅผ ์๋ณตํ๋ฉฐ ๋ฏธ์ธํ ํ๋ ์ ๋๋(Stuttering)์ด ๋ฐ์ํฉ๋๋ค.
Lynx์ **Main Thread Script (MTS)**๋ ํน์ ์ ์ค์ฒ ํธ๋ค๋ฌ๋ฅผ ๋ฉ์ธ UI ์ค๋ ๋์์ ์ง์ ์ธ๋ผ์ธ์ผ๋ก ์ฆ์ ์คํํ๋๋ก ๋ง๋ญ๋๋ค!
// src/DraggableBox.tsx
import './DraggableBox.css';
export function DraggableBox() {
// ๐ก 'main-thread' ํค์๋๋ฅผ ์ฌ์ฉํ๋ฉด ์ด ํจ์๋ ๋ฉ์ธ UI ์ค๋ ๋์์๋ง ์ง์ ์คํ๋ฉ๋๋ค!
const onTouchMoveOnMain = (event: any) => {
'main-thread';
const touch = event.touches[0];
// UI ์ค๋ ๋์์ ๋ค์ดํฐ๋ธ ์๋ฆฌ๋จผํธ์ transform ์คํ์ผ์ 0ms ๋๋ ์ด๋ก ์ฆ๊ฐ ๊ฐฑ์ !
event.currentTarget.setStyleProperty(
'transform',
`translate3d(${touch.clientX - 50}px, ${touch.clientY - 50}px, 0px)`
);
};
return (
<view className="canvas-area">
<view
className="floating-box"
// โก main-thread: ์ ๋์ฌ๋ฅผ ๋ถ์ฌ ๋ฉ์ธ ์ค๋ ๋ ์ง์ ๋ฐ์ธ๋ฉ
main-thread:ontouchmove={onTouchMoveOnMain}
>
<text className="box-text">๋๋๊ทธํด ๋ณด์ธ์ (120fps)</text>
</view>
</view>
);
}
6. [3๋จ๊ณ] ์ค๋ฌด ์์ฉ ํจํด 1: ๋๊ท๋ชจ ์ธํผ๋ํธ ํผ๋ ๊ฐ์ํ (<list> ์ปดํฌ๋ํธ)
ํฑํก(TikTok) ์ฑ๊ณผ ๊ฐ์ด ์์ฒ ๊ฐ์ ์นด๋ ๋ชฉ๋ก์ ๋ฉ๋ชจ๋ฆฌ ๋์ ์์ด 60fps ~ 120fps๋ก ์ค์๊ฐ ์ฌํ์ฉ(Recycling)ํ๋ ๊ฐ์ํ ๋ฆฌ์คํธ ์์ ์ ๋๋ค.
// src/VideoFeedList.tsx
import { useState } from '@lynx-js/react';
import './VideoFeedList.css';
interface FeedItem {
id: string;
title: string;
author: string;
coverUrl: string;
likes: number;
}
export function VideoFeedList() {
const [items, setItems] = useState<FeedItem[]>([
{ id: '1', title: 'Lynx๋ก ์ ์ํ ๊ณ ์ฑ๋ฅ ํฑํก ํด๋ก ', author: '@techworld', coverUrl: 'https://picsum.photos/400/600?1', likes: 12400 },
{ id: '2', title: '๋์ผ ์ค๋ ๋ ์ํคํ
์ฒ์ ๋น๋ฐ', author: '@bytedance_dev', coverUrl: 'https://picsum.photos/400/600?2', likes: 8900 },
{ id: '3', title: '120fps ์คํฌ๋กค์ ๋น๊ฒฐ', author: '@frontend_pro', coverUrl: 'https://picsum.photos/400/600?3', likes: 34500 },
]);
// ์คํฌ๋กค ์ตํ๋จ ๋๋ฌ ์ ์ถ๊ฐ ๋ฐ์ดํฐ ๋ก๋ (Infinite Scroll)
const handleScrollToLower = () => {
console.log('[Feed] ์ถ๊ฐ ํผ๋ ๋ฐ์ดํฐ ํ์นญ...');
const nextId = String(items.length + 1);
setItems((prev) => [
...prev,
{
id: nextId,
title: `์ ๊ท ํผ๋ ์์ดํ
#${nextId}`,
author: `@creator_${nextId}`,
coverUrl: `https://picsum.photos/400/600?${nextId}`,
likes: 1500,
},
]);
};
return (
<view className="feed-container">
{/* โจ Lynx ๋๊ท๋ชจ ๊ฐ์ํ ๋ฆฌ์คํธ */}
<list
className="feed-list"
scroll-orientation="vertical"
bindscrolltolower={handleScrollToLower}
lower-threshold={100}
>
{items.map((item) => (
// ๊ฐ ๋ฆฌ์คํธ ์์ดํ
์ list-item ํ๊ทธ๋ก ๊ฐ์ธ๋ฉฐ item-key๋ฅผ ํ์ ์ง์
<list-item key={item.id} item-key={item.id} className="feed-card">
<image src={item.coverUrl} className="card-cover" mode="aspectFill" />
<view className="card-info">
<text className="card-title">{item.title}</text>
<view className="card-meta">
<text className="card-author">{item.author}</text>
<text className="card-likes">โค๏ธ {item.likes.toLocaleString()}</text>
</view>
</view>
</list-item>
))}
</list>
</view>
);
}
/* src/VideoFeedList.css */
.feed-container {
display: flex;
flex-direction: column;
width: 100%;
height: 100vh;
background-color: #000000;
}
.feed-list {
width: 100%;
height: 100%;
}
.feed-card {
display: flex;
flex-direction: column;
width: 100%;
height: 480px;
position: relative;
margin-bottom: 12px;
background-color: #111827;
border-radius: 12px;
overflow: hidden;
}
.card-cover {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.card-info {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
padding: 16px;
background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
}
.card-title {
font-size: 18px;
font-weight: 700;
color: #ffffff;
margin-bottom: 6px;
}
.card-meta {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.card-author {
font-size: 14px;
color: #38bdf8;
}
.card-likes {
font-size: 14px;
color: #f43f5e;
}
7. [3๋จ๊ณ] ์ค๋ฌด ์์ฉ ํจํด 2: Native Modules (๋ค์ดํฐ๋ธ ๊ธฐ๋ฅ ๋ธ๋ฆฟ์ง ํธ์ถ)
์ค๋งํธํฐ์ ํ ํฑ ์ง๋(Haptics), ์นด๋ฉ๋ผ, ์์ฒด ์ธ์ฆ(FaceID), ๋ฐฐํฐ๋ฆฌ ์๋ ๋ฑ OS ๋ค์ดํฐ๋ธ ๊ธฐ๋ฅ์ Lynx ๋ชจ๋ ์ธํฐํ์ด์ค๋ฅผ ํตํด ํธ์ถํฉ๋๋ค.
// src/DeviceUtils.ts
// NativeModules ์ธํฐํ์ด์ค ์ ์ธ
interface DeviceModule {
vibrate(durationMs: number): void;
getBatteryLevel(): Promise<number>;
}
export const NativeDevice: DeviceModule = (globalThis as any).lynx?.getJSModule('DeviceModule') || {
vibrate: (ms: number) => console.log(`[Mock Native] ํ
ํฑ ์ง๋ ์คํ: ${ms}ms`),
getBatteryLevel: async () => 95,
};
์ปดํฌ๋ํธ์์ ํธ์ถ:
import { NativeDevice } from './DeviceUtils';
function HapticButton() {
const handlePress = async () => {
// 1. ๋ค์ดํฐ๋ธ ํ
ํฑ ์ง๋ ํผ๋๋ฐฑ
NativeDevice.vibrate(50);
// 2. ๋ฐฐํฐ๋ฆฌ ์ํ ์กฐํ
const battery = await NativeDevice.getBatteryLevel();
console.log(`ํ์ฌ ๋ฐฐํฐ๋ฆฌ ์๋: ${battery}%`);
};
return (
<view className="haptic-btn" bindtap={handlePress}>
<text className="btn-label">ํ
ํฑ ์ง๋ ํฐ์น</text>
</view>
);
}
8. ์ค๋ฌด ์ฃผ์์ฌํญ & ํ๋ก๋์ ์ฒดํฌ๋ฆฌ์คํธ (Troubleshooting & Checklist)
โ ๏ธ ์ด๋ณด์๊ฐ ํํ ๊ฒช๋ ์ค์ Top 5
- ๋ธ๋ผ์ฐ์ DOM ์ ์ฉ API(
document,window) ์ง์ ํธ์ถ:- Lynx๋ ๋ธ๋ผ์ฐ์ DOM์ด ์๋ C++ ๋ค์ดํฐ๋ธ ์์ ฏ ์์ง์
๋๋ค.
document.getElementById()๋window.addEventListener()๋ฅผ ํธ์ถํ๋ฉด ์ฆ์ReferenceError๊ฐ ๋ฐ์ํฉ๋๋ค. ์๋ฆฌ๋จผํธ ์ ์ด๋ Lynx Selector API ๋๋ React Ref๋ฅผ ์ฌ์ฉํ์ธ์.
- Lynx๋ ๋ธ๋ผ์ฐ์ DOM์ด ์๋ C++ ๋ค์ดํฐ๋ธ ์์ ฏ ์์ง์
๋๋ค.
<view>ํ๊ทธ ๋ด๋ถ์ ํ ์คํธ ๋ฌธ์์ด ์ง์ ์ฝ์ :- HTML์ฒ๋ผ
<div>Hello</div>๋ก ์ฐ๋ฉด ํ ์คํธ๊ฐ ํ๋ฉด์ ํ์๋์ง ์์ต๋๋ค. ๋ชจ๋ ๋ฌธ์์ด์ ๋ฐ๋์<text>Hello</text>๋ก ๊ฐ์ธ์ผ ๋ ๋๋ง๋ฉ๋๋ค.
- HTML์ฒ๋ผ
- ๋๊ท๋ชจ ํผ๋์์
<scroll-view>๋ฅผ ์ฌ์ฉํ์ฌ OOM(Out of Memory) ํฌ๋์ ์ ๋ฐ:- ๋ฐ์ดํฐ๊ฐ 100๊ฐ ์ด์์ธ ๋ชฉ๋ก์
<scroll-view>๋ฅผ ์ฌ์ฉํ๋ฉด ๋ณด์ด์ง ์๋ ํ๋ฉด์ ๋ชจ๋ ๋ค์ดํฐ๋ธ ๋ทฐ๊ฐ ๋ฉ๋ชจ๋ฆฌ์ ๊ทธ๋๋ก ๋จ์ ์ฑ์ด ๊ฐ์ ์ข ๋ฃ๋ฉ๋๋ค. ๋๊ท๋ชจ ๋ชฉ๋ก์ ๋ฐ๋์<list>์<list-item>์ปดํฌ๋ํธ๋ก ๊ฐ์ํ(Virtualization)ํ์ธ์.
- ๋ฐ์ดํฐ๊ฐ 100๊ฐ ์ด์์ธ ๋ชฉ๋ก์
- Main Thread Script(MTS) ๋ด๋ถ์์ ๋ฌด๊ฑฐ์ด ๋น์ฆ๋์ค ๋ก์ง ์คํ:
main-threadํจ์ ๋ด๋ถ์์ ๋๊ท๋ชจ JSON ํ์ฑ์ด๋ ๋ณต์กํ ๊ณ์ฐ์ ์ํํ๋ฉด 120fps ๋ ๋ ๋ฃจํ๊ฐ ์ฐจ๋จ๋์ด ์ฌ๊ฐํ UI ํ๋ฆฌ์ง์ด ๋ฐ์ํฉ๋๋ค. MTS๋ ์ค์ง ์คํ์ผ, ์ขํ, ์ ๋๋ฉ์ด์ ์ ์ด์๋ง ์ฌ์ฉํ์ธ์.
- CSS ์ ํ์(Selector) ์ค์ฉ ๋ฐ ์์ ์ ํ:
- Lynx๋ ๊ณ ์ ๋ ์ด์์ ๊ณ์ฐ์ ์ํด ๋จ์ผ ํด๋์ค ์ ํ์(
.my-class)๋ฅผ ๊ถ์ฅํ๋ฉฐ, ๊น์ ๋ณตํฉ ์ ํ์(.container > div .item)๋ ์ฑ๋ฅ ์ ํ๋ฅผ ์ผ์ผํฌ ์ ์์ต๋๋ค.
- Lynx๋ ๊ณ ์ ๋ ์ด์์ ๊ณ์ฐ์ ์ํด ๋จ์ผ ํด๋์ค ์ ํ์(
๐ ํ๋ก๋์ ๋น๋ & ๋ฐฐํฌ ์ฒดํฌ๋ฆฌ์คํธ (Rspeedy Build)
# 1. ํ๋ก๋์
์ต์ ํ ๋ฒ๋ค ๋น๋
pnpm build
# 2. ๋ฒ๋ค ์ฐ์ถ๋ฌผ (.lynx ๋ฐ์ด๋๋ฆฌ ๋ฐ ์ ์ ์์
) ํ์ธ
ls -la dist/
- Rspeedy ๋ฒ๋ค ์ฌ์ด์ฆ ์ต์ ํ: ์ฌ์ฉํ์ง ์๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํธ๋ฆฌ์์ดํน(Tree-shaking) ๊ฒ์ฆ
- ์์ ์ฌ์ ๋ฒ๋ค๋ง: ๋คํธ์ํฌ ์์ฒญ์ ์ต์ํํ๊ธฐ ์ํด ์์ ์์ด์ฝ์ base64 ์ธ๋ผ์ธํ ์ฒ๋ฆฌ
- Dual-Thread ์๋ฌ ๊ฒฝ๊ณ(Error Boundary) ๋ฑ๋ก: ๋ฐฑ๊ทธ๋ผ์ด๋ JS ์ค๋ฅ๊ฐ ๋ฐ์ํด๋ ๋ค์ดํฐ๋ธ ์ฑ ์ ์ฒด๊ฐ ๋น์ ์ ์ข ๋ฃ(Crash)๋์ง ์๋๋ก ํด๋ฐฑ ํ๋ฉด ์ฒ๋ฆฌ
- ๋ฆด๋ฆฌ์ค ์๋ช ๋ฐ ProGuard ์ค์ : Android/iOS ๋ค์ดํฐ๋ธ ํธ์คํธ ์ฑ ๋ฐฐํฌ ์ ProGuard ๋ฃฐ ๋ฐ ๋๋ ํ ๊ฒ์ฆ ์๋ฃ
์๊ฒฌ ๋ฐ ์ง๋ฌธ
0์์ง ๋ฑ๋ก๋ ์๊ฒฌ์ด ์์ต๋๋ค. ์ฒซ ๋ฒ์งธ ๋๊ธ์ ๋จ๊ฒจ๋ณด์ธ์!
๋๊ธ ์์
๋๊ธ ์ญ์