# Hydration and adoption (/docs/concepts/adoption) **Hydration** is the moment your app's JavaScript takes over the snapshot screen. **Adoption** is how it does that: instead of mounting its first render as new views, BakeNative matches it against the snapshot and hands the existing views to your app. The term comes from Octane's native renderer design, where a runtime's first commit is "accepted in adoption mode": it describes the screen that is already there rather than instructing the host to build it again. ## The sequence [#the-sequence] ```text launch ├─ draw the snapshot (no JS) phase: frame ├─ Hermes renders the first commit (in parallel) └─ the hydration strategy fires phase: hydrating ├─ match → views handed to your app phase: adopted (0 views created) │ held taps delivered └─ mismatch → snapshot dropped, normal render phase: remounted no snapshot → normal render phase: mounted ``` ## How the match works [#how-the-match-works] BakeNative flattens both trees in the same order (parents before children, text nodes included) and compares them row by row: 1. Both trees must have the same number of rows. 2. Each row must have the same element type (`div`, `button`, text …) and the same parent. 3. Text inside a block of text must be identical. Props, styles and event handlers are not compared. Once the views belong to your app, its normal update path applies them, exactly as it would after any render. That keeps the match cheap and robust: a different class name or handler does not throw the snapshot away. When the trees match, each snapshot view is bound to the matching element of your app. No view is created, which is why `viewsCreatedOnAdopt` is expected to be `0`. ## When the trees differ [#when-the-trees-differ] The snapshot is dropped and your app's first commit is mounted from scratch. Nothing is lost except time, and the launch metrics record the first difference so you can fix the cause ([Troubleshooting](/docs/guides/troubleshooting#the-screen-rebuilds-on-launch-remounted)). ## Early input [#early-input] Because the snapshot is real native views, it can be tapped before JavaScript is ready. BakeNative holds those events while the phase is `frame` or `hydrating`. After adoption it maps each one from the snapshot view to your app's element and delivers it if that element has a handler for the event, in the original order. Held events are dropped rather than delivered when the match failed or the snapshot came from a different bundle. ## Relation to Octane [#relation-to-octane] Octane hydrates server-rendered HTML with `` per boundary: the HTML is shown until the boundary's condition fires, then the boundary becomes interactive. BakeNative applies the same idea to a native screen: the snapshot plays the server HTML, and `HydrationStrategy` plays `when` for the whole screen, with the same strategy names (`load`, `idle`, `interaction`, `never`). # Architecture (/docs/concepts/architecture) BakeNative has three parts. The React or Octane adapter turns the app’s committed changes into a renderer-independent batch. One Rust core turns what it renders into laid-out, painted boxes. A thin host per platform shows those boxes as native views. The build adds a fourth part: it records your first screen ahead of time, so a device can show it before JavaScript runs, and JavaScript then takes over the views already on screen. 1. **Build.** `bake build --bake` compiles the app to Hermes bytecode (`app.hbc`), runs it once and records its first commit with its styles as `app.baked`. 2. **Launch.** The main thread lays out `app.baked` with the Rust core and draws the native views. After the first frame commits, the main thread starts Hermes. 3. **Hydration.** When the hydration strategy fires, the core compares the first commit with the snapshot. If they are the same tree, your app takes over the views on screen and none are created (adoption). If not, the snapshot is replaced by a normal render. ## The layers [#the-layers] | Layer | Where it lives | What it does | | --- | --- | --- | | Your app | `src/App.tsx` (React) or `src/App.tsrx` (Octane), `src/styles.css` | Components and styles. The same source builds for every target | | `bake build` | `packages/core` | Bundles the selected renderer with Vite, checks every native input, compiles to Hermes bytecode, bakes the first screen | | JS runtime | Hermes, one runtime per BakeNative view | Runs `app.hbc` with the selected adapter and sends each commit to the core as a binary batch | | Rust core | `native/rust` | CSS, layout, line breaking, paint, SVG, events, focus, accessibility, the first screen and adoption. The same code on every native target | | Host | `native/uikit`, `native/appkit`, `native/android`, `native/rust/crates/bake-host-windows` | Creates and updates platform views from the core's op buffer, draws text and paint, and sends input back | On the web, none of this runs: `dist/web` is an ordinary Vite site and the browser does styling, layout and painting. ## From source to bundle [#from-source-to-bundle] `bake build` compiles your app once per target from the same source ([CLI](/docs/reference/cli)). - **Web.** A normal Vite build that renders to the DOM. - **Native (`ios`, `mac`, `android`, `windows`).** One script per target that renders through the selected native renderer. `import.meta.env.BAKE_TARGET` is a constant, so branches for other platforms are removed. `hermesc` compiles the script to `app.hbc`. Each native target gets its own folder: | File | What it is | | --- | --- | | `app.hbc` | Your app as Hermes bytecode. There is no parse or compile step at launch | | `app.css` | The app's stylesheet, read by the core | | `app.baked` | The [first-screen snapshot](/docs/concepts/snapshot), with `--bake` | | `manifest.json` | Hashes that pair `app.hbc` with `app.baked`, and what the bundle **requires** from the runtime and its native modules ([manifest](/docs/reference/manifest)) | ### Fail-closed checks [#fail-closed-checks] A native target supports a subset of the web platform. Everything outside it is a build error, not a silent difference on the device. `bake build` checks each native bundle against two allow lists: - `packages/core/native-support.json`: elements, attributes, event handlers and JavaScript globals. - The Rust CSS lint (`bake-css-lint`, `native/rust/crates/bake-css`): CSS properties, values and selectors, with the same parser the core uses. Each error names the file, the line, why the input is not supported and what to use instead. The [support list](/docs/reference/support) is generated from the same two lists. `// bake-allow ` on a line accepts one finding when you know the difference is harmless ([Writing your app](/docs/guides/writing-apps#unsupported-is-a-build-error)). ### The AOT fast path [#the-aot-fast-path] Octane's compiler turns templates into **template programs**: static host plans that the runtime mounts in one step, with per-binding patchers for the parts that change. Some template shapes leave that path, for example a `@for` without a key, a class built from data, or a signal read during render. They still work, but the runtime takes a slower, generic path. `bake build` reads every `.tsrx` file with OXC (the parser Octane's compiler runs on) and reports each such site, with the fix. Strict AOT is the default: every finding is an error and the build stops before it writes a target. To keep one site, add `// bake-allow -- `. To turn strict AOT off for the app, pass `--no-strict-aot` or set `"bakenative": { "strictAot": false }` in `package.json`; findings are then warnings. `bake aot` runs the check alone. The rules are in the [CLI reference](/docs/reference/cli#aot-fast-path-check). ## Baking the first screen [#baking-the-first-screen] With `--bake`, `bake build` runs `app.hbc` once in Hermes on the build machine and records your app's **first commit** (the element tree of its first render). The bake records the prepared render before Octane runs ref callbacks or effects. It resolves the CSS of that tree for light and dark mode and writes the result to `app.baked`. A requested bake must fail if the first render throws or produces no first commit. The diagnostic should identify the failing target, the app source when available, and what prevented the first render. For values that only exist at runtime, give the first render a deterministic value and apply the real value as a later update. See [Keep the first render deterministic](/docs/guides/writing-apps#keep-the-first-render-deterministic). The snapshot holds no positions or sizes. Fonts, screen size, safe-area insets and native control sizes differ per device, so the device lays the snapshot out at launch. The cascade does not read the platform, so a page without platform code bakes to the same styles for every target. Elements whose style depends on the viewport (media queries, viewport units) are marked during the bake. On the device only those are restyled. See [First-screen snapshot](/docs/concepts/snapshot) for what is stored and [`.baked` reference](/docs/reference/baked) for the byte layout. ## Launch: snapshot, then adoption [#launch-snapshot-then-adoption] 1. The core reads `app.baked` and lays it out at the view's real size with the platform's fonts. The host draws it on the main thread. 2. After the host commits that frame, Hermes loads `app.hbc` on the main thread and your app renders its first commit. When the [hydration strategy](/docs/guides/hydration) fires, the core compares that first commit with the snapshot. If both describe the same tree, it hands the views already on screen to your app and creates none (**adoption**). Taps on the snapshot that arrived before adoption are delivered to the matching elements. If the trees differ, the snapshot is dropped and the first commit is mounted from scratch. A snapshot baked from a different `app.hbc` is never adopted. See [Hydration and adoption](/docs/concepts/adoption). Without `--bake` there is no snapshot, and the first screen appears after the first commit. ## Run time: JS → core → host [#run-time-js--core--host] ```text Hermes (JS thread) Rust core Host (main thread) Host commit ── batch ─▶ restyle, lay out, paint ── ops ─▶ create / update views ◀─ events ─ DOM events, focus, a11y ◀─ events ─ touch, keys, scroll, resize ``` - **JS → core.** The host runtime (`packages/core/host-runtime.js`) accepts committed host mutations from both adapters. React uses React’s reconciler to generate updates, and Octane uses its universal renderer. Each commit becomes one binary batch (the `OCB2` stream, `native/rust/schema/batch.oschema`). The runtime refuses a bundle built for a different batch format (`batchDigest` in `manifest.json`). - **Core.** `bake-core` applies the batch to its document, restyles with `bake-css`, lays out with `bake-layout` (block, flex and grid), breaks lines with `bake-text` and builds paint records. It also routes DOM events along their capture and bubble path, tracks focus and keeps the accessibility tree. - **Core → host.** The core writes an **op buffer**: what changed in the view tree, with frames, paint, text runs and accessibility roles. Hosts read it with code generated from one schema (`native/rust/schema/host.oschema`) for Rust, Swift, Kotlin and C. A host built against a different schema is refused when the root opens. - **Host → core.** Input, scrolling, text field edits, control changes, resizes and color scheme changes go back as an **event buffer**. Layout and paint are computed once, in the core, and the result is the same on every native target: Chrome is the reference that parity tests compare against ([Testing](/docs/testing)). The host contributes only what the platform must: text shaping and glyph drawing, real text fields and native form controls, scrolling, input, the device's fonts and color scheme, and the platform accessibility API. See [Rendering](/docs/concepts/rendering) for what each platform does. ## Hosts [#hosts] Every host is thin: it creates a view for each box the core asks for, applies frames and paint, and forwards input. | Host | Views | Text | Accessibility | | --- | --- | --- | --- | | iOS | UIKit views, Core Animation | CoreText | UIAccessibility | | macOS | AppKit views, Core Animation | CoreText | NSAccessibility | | Android | Android views, `Canvas` | Minikin shaping, ICU line breaks | Android accessibility | | Windows | DirectComposition visuals in a child `HWND`, Direct2D | DirectWrite | UI Automation | Each host is one view you embed in an existing app: `BakeNativeView` / `BakeNativeViewController` (UIKit) or `BakeNativeSurface` (SwiftUI) on iOS, `BakeNativeView` (AppKit) or `BakeNativeSurface` (SwiftUI) on macOS, and `BakeNativeView` on Android and Windows. See the guides for [iOS](/docs/guides/ios), [macOS](/docs/guides/macos), [Android](/docs/guides/android) and [Windows](/docs/guides/windows). ## Native modules [#native-modules] Native code reaches JavaScript as **JSI host functions** under `globalThis.native..`. JS calls them directly, with no message bus. Async functions return a Promise. A module is declared once as a TypeScript spec (`.native.ts`); each host implements the contract generated from it. | Platform | Language | Implemented as | | --- | --- | --- | | iOS, macOS | Swift | a class conforming to the generated `Spec` protocol (`async throws` for async members) | | Android | Kotlin | a class extending the generated `Spec` abstract class (`suspend fun` for async members) | | Windows | Rust | a type implementing the generated `Spec` trait | Modules are registered per root and installed before the bundle runs, so each view's runtime sees only its own modules. The first-party modules (`Clipboard`, `Linking`, `Share`) are build units of their own: SwiftPM products, Gradle projects and cargo features. `bake build` records the ones the bundle calls in `requires.modules`, and generates the registration that links exactly those (`BakeNativeAppModules`, [System modules](/docs/guides/system-modules#only-the-modules-an-app-uses)), so an app does not carry a module it does not use. `bake native types` writes the TypeScript declarations from the specs in `native//` (`--schema` adds the modules of a schema a host wrote for modules that have no spec). A module can also send events to JS: the spec declares `onX(listener): Unsubscribe` and each contract gets an emitter ([Events](/docs/guides/native-modules#events)). Native calls are not available during the bake: do not call them during render. See [Native modules](/docs/guides/native-modules). ## App packages and OTA compatibility [#app-packages-and-ota-compatibility] An **app package** is one BakeNative app as a native library: its bundle, its first screen and its own native modules. A host app links the shared runtime once and any number of packages next to it ([App packages](/docs/guides/packaging)). `bake package` builds them for iOS (`.xcframework`); Android packages (`.aar`) are planned. JS bundles can ship over the air; native code ships only with an app release. Whether a downloaded bundle may run is decided item by item: - The bundle's `manifest.json` lists what it **requires**: the renderer ops, events and CSS properties it uses, and the signature of each native function it calls. - The runtime and the package list what they **provide**. - The bundle runs when every requirement is provided with the same shape (**requires ⊆ provides**). Otherwise the device refuses it with the reasons and runs the package's embedded bundle. So adding a native function or changing native code behind the same signature does not break existing bundles. Removing or reshaping something a bundle uses does. `bake release check` runs the same comparison in CI before an OTA release. ## What is not supported [#what-is-not-supported] - Anything outside the allow lists is a build error on native targets, never a fallback. The [support list](/docs/reference/support) shows each item per target. - Some features differ between hosts (for example a few CSS effects on Android). Those are build errors on the targets that lack them, listed in the support list's first table. - Native calls during render are not supported, because the bake has no native modules. ## Where to read next [#where-to-read-next] # Comparison (/docs/concepts/comparison) The scrolling benchmark runs the React adapter on a physical iPhone. The startup benchmark runs the Octane adapter on an iOS simulator. ## Approach [#approach] | | BakeNative | Exact | React Native (Expo) | Flutter | | --- | --- | --- | --- | --- | | UI language | React `.tsx` or Octane `.tsrx`, with shared native styling | Its own UI language, with TypeScript or Rust logic | JSX with React | Dart widgets | | Drawn with | Native views (UIKit, AppKit, Android views, DirectComposition on Windows) | Native hosts per platform | Native views | Its own renderer | | First screen | Baked at build time and drawn before JavaScript runs; JavaScript then adopts the views on screen | Baked into a build-time plan; JavaScript loads after the first pixel | JavaScript runs the bundle, then renders | Dart AOT code builds the first frame | | Web | The same source as a normal Vite web build | Compiled plan plus a small runtime | React Native Web (separate renderer) | Flutter web | | Into an existing app | One view or view controller (`BakeNativeViewController`, `BakeNativeView`) | Not checked | Supported (brownfield) | Supported (add-to-app) | The Exact column is from reading its repository on 2026-11-25. ## Scrolling a React List on iPhone 12 [#scrolling-a-react-list-on-iphone-12] Nitro UI used less CPU and memory while scrolling the same 5,000 coins. Both Release apps delivered 60 display-link callbacks per second. The probe drove the list at 24,000 points per second in each direction on iOS 26.6.1 with live prices paused. Each table entry is the median of five launches. CPU is milliseconds of process CPU time per second of scrolling. Footprint is the memory charged to the process when scrolling stopped. | Release app | Down CPU (ms/s) | Up CPU (ms/s) | End footprint (MiB) | | --- | ---: | ---: | ---: | | BakeNative React List | 576.7 | 529.3 | 50.6 | | Nitro UI 0.2.0 | 385.3 | 372.8 | 27.5 | Every run in this section, including the later series below, used the earlier BakeNative rows built from `div`, `span` and `p` elements. The benchmark rows now use the built-in `View` and `Text`, and the phone comparison has not been rerun with them. BakeNative recycled row views, measured text and rasterized labels and inline SVG into bitmaps. Its largest CPU sample group was the shared UIKit bitmap renderer. Nitro used reusable collection cells, native labels and a native chart. The process footprint includes the runtime, row data and graphics allocations. The share of the memory gap attributable to each remains open. [Per-launch results and CPU profiles](https://github.com/gronxb/bake-native/blob/main/benchmarks/crypto-list/results/iphone12-react-scroll-costs/README.md) A later BakeNative change limited bitmap drawing near the viewport. In a separate five-pair series on the same phone, the updated React List used **521.5 ms/s down, 499.1 ms/s up and 50.2 MiB** at the end. A separate capture test found that a recycled row could briefly show the coin from 36 rows away during a fast scroll. Display-link timing alone misses that defect. [Viewport optimization and paired results](https://github.com/gronxb/bake-native/blob/main/benchmarks/crypto-list/results/iphone12-viewport-bitmap/guarded/README.md) · [Moving-row captures](https://github.com/gronxb/bake-native/blob/main/benchmarks/crypto-list/results/iphone12-recycled-row-captures/README.md) ## Measured: BakeNative, Expo and a native app [#measured-bakenative-expo-and-a-native-app] One shop demo app, built three ways: with the BakeNative Octane adapter, with Expo, and as a plain SwiftUI app. The video shows, per app, the take nearest that app's median: first a cold start (tap the app icon), then a screen opened inside an existing native app (tap a row). Its numbers are the medians in the table below. Conditions: iOS simulator (iPhone Duo, iOS 27.2) on a Mac mini M4 shared with other builds, Release builds (Hermes bytecode in the BakeNative and Expo apps), the same screens, photos and launch screen, the same 10 MB product catalog and the same search-index job at startup, 7 takes per app with the apps alternating, median. Host load: about 30 during the new-app takes; falling from about 200 to 16 during the existing-app takes (every app saw the same spread). | Measure | BakeNative | Native (SwiftUI) | Expo | | --- | --- | --- | --- | | Cold start: launch → first screen | 2188 ms | 2162 ms | 2832 ms | | Existing app: tap → screen content | 40 ms | 45 ms | 1172 ms | | Existing app: tap → screen content, React Native started ahead of time | – | – | 43 ms | All three apps carry the same 10 MB catalog and search index. BakeNative renders its first screen at build time (`app.baked`); the native app decodes the catalog in the background; Expo renders after its JavaScript has run. On this run BakeNative is at the level of the native app in both scenes. Expo is slower to first content unless React Native is started ahead of time. Baseline: an empty UIKit app with the same launch screen reaches its settled navigation bar in 1637 ms after a cold launch; the BakeNative app takes 1768 ms (5 takes each, median, load about 5). Most of a simulator cold launch is iOS itself; BakeNative adds about 130 ms over an app that does nothing. These startup times include simulator overhead. The same three-way startup comparison has yet to run on a physical iPhone. Every take, the medians, the setup and the method are in the repository: [`docs/data/race/README.md`](https://github.com/gronxb/bake-native/blob/main/docs/data/race/README.md). ## Not measured [#not-measured] | Comparison | Status | | --- | --- | | BakeNative and Exact, cold start on the same iPhone with the same probe | Not measured | | BakeNative and Exact, list benchmark (fps, late frames, idle CPU, peak memory) | Not measured | | BakeNative and Expo on a real device | Not measured | | BakeNative and Flutter, any number | Not measured | | App size against any of the three | Not measured | Exact publishes its own cold-start and list numbers from real devices. They were measured with a different app and a different probe, so they are not compared here. For BakeNative's own numbers and their conditions, see [Performance](/docs/concepts/performance) and [Embedding cost](/docs/guides/embedding-cost). # Launch overview (/docs/concepts/overview) Native apps built on a JavaScript runtime usually start the same way: launch the app, start the JS engine, run the bundle, render, create every view, and only then show something. BakeNative moves most of that work out of the launch. ## Three stages [#three-stages] ### 1. Build [#1-build] `bake build` compiles your app from the same source for each selected target: - For **web**, a normal browser build that renders to the DOM. - For each **native** target, a single script that renders through the selected adapter, compiled by `hermesc` into Hermes bytecode (`app.hbc`). Branches on `import.meta.env.BAKE_TARGET` for other platforms are removed. ### 2. Bake [#2-bake] A native React build, or an Octane build requesting a bake, runs your bytecode once in Hermes, takes the **first commit** (the element tree your app renders on its first pass), resolves its CSS for light and dark mode, and writes the result as the **[first-screen snapshot](/docs/concepts/snapshot)** (`app.baked`). The snapshot holds no positions or sizes, because those depend on the device. ### 3. Launch [#3-launch] The host lays out the snapshot at the view's real size and draws it as native views. After the first frame commits, Hermes loads `app.hbc` on the host's main thread and renders your app's first commit. When the [hydration strategy](/docs/guides/hydration) says so, BakeNative compares Hermes's first commit with the snapshot. If they describe the same tree, it hands the views already on screen to your app instead of creating new ones ([adoption](/docs/concepts/adoption)). From then on, your app updates those views like any other render. ## Brownfield first paint [#brownfield-first-paint] When a tap in an existing native app opens a BakeNative screen, the destination's first visible frame should already contain the screen's content. Measure the time from the tap to that frame. Keep content visible throughout the transition and while the runtime takes over. A white or background-only placeholder frame counts as a regression. BakeNative commits the baked first screen before starting Hermes. When the trees match, the runtime [adopts the native views already on screen](/docs/concepts/adoption). After adoption, the renderer sends committed changes to BakeNative. The core reuses cached style and layout where it can, and the host reuses the existing views to apply [the changes the update requires](/docs/concepts/performance#updates-after-launch). Verify first paint with a Release build on a physical Android device. Compare cache hits and misses separately. Use the device's displayed frames to check for blank frames, and measure runtime adoption and subsequent update costs separately from tap-to-content. See [Brownfield](/docs/guides/brownfield) for how to embed a screen. ## Why it is fast [#why-it-is-fast] - **Nothing to compute at first paint.** Your CSS was resolved at build time, and drawing the snapshot is one forward pass over its rows. - **JavaScript is off the critical path.** It runs in parallel with the first paint instead of before it. - **No second build of the screen.** Adoption reuses the views that are already visible, so the takeover costs milliseconds and nothing flickers. ## Use built-in views first [#use-built-in-views-first] Build each screen from your adapter's built-in native views whenever one can express the UI. Both adapters export these built-in views from their root import. | Purpose | React (`@bake-native/react`) | Octane (`@bake-native/octane`) | | --- | --- | --- | | Container | `View` | `View` | | Text | `Text` | `Text` | | Image | `Image` | `Image` | | Long list of fixed-height rows | [`List`](/docs/guides/lists#react-list) | [`VirtualList`](/docs/guides/lists#octane-virtuallist) | | Press target | `Pressable` | No built-in view. Use ` } } ``` - Native calls happen in handlers, never during render: the build-time snapshot has no native modules. - The same bundle also serves a SwiftUI screen that has no order screen, so the call is guarded with `hasNative('OrderScreen')`. That makes the module optional: a screen without it still starts. Unguarded, the [boot check](/docs/guides/module-registry#boot-check) would refuse to start a screen that does not register it. The complete app is `examples/ios-brownfield` in the repository, with the card in `examples/brownfield-embed`. ## Several apps in one host [#several-apps-in-one-host] A host can show screens from more than one React or Octane app. Two ways: - **Bundles in the app.** Each app is built with `bake build` and copied into the host. One app-layer registry covers the modules of every bundle: `bake native link` takes several `--bundle` options and writes the registration of their union ([System modules](/docs/guides/system-modules)). - **App packages.** Each app is its own native part with its own modules, on one shared runtime. The host adds the parts and calls their entry points: [Micro-native packages](/docs/guides/micro-native). ## Cost [#cost] What one Octane screen adds to an existing app (time to the first frame, binary size, memory) is measured on [Embedding cost](/docs/guides/embedding-cost). # Comparing native and web (/docs/guides/dev-tool) The dev tool is a macOS app that ships with the BakeNative checkout. Run it from there: ```sh pnpm devtool ``` It has two tabs: **Octane**, for checking an app, and **Hermes**, a JavaScript playground for the runtime itself. ## The Octane tab [#the-octane-tab] Edit `.tsrx` and CSS in the tab's editor (it starts from a sample project; paste in the components you want to check). Every edit rebuilds with `bake build --target web,mac`, bakes a snapshot and launches it, so you always see the current code. ### Preview modes [#preview-modes] | Mode | Shows | | --- | --- | | Native | Your app drawn by BakeNative with AppKit views | | Web | The web build in a WebKit view | | Side by side | Both, next to each other | | Overlay | Web on top of native, with an opacity slider | The **Hydrate** picker switches the [hydration strategy](/docs/guides/hydration) so you can watch the snapshot, the takeover and held taps at each setting. ### Inspectors [#inspectors] | Inspector | Use it to | | --- | --- | | Native vs Web | Find layout differences: every element's position and size on both sides, with the difference | | Launch | Read the launch metrics: phases, timings, held and replayed taps | | Frame | See what the snapshot contains, row by row | | Batches | Follow updates after launch: what caused each one, how long JS and native took | | Host tree | See the native element tree your app produced | | Console | Read `console.log` output from Hermes | | Compiled | Read what the compiler made of `App.tsrx` | The launch timeline above the preview shows snapshot read, draw, Hermes start and takeover with their durations. When the first render did not match the snapshot it shows where they differed. ## The Hermes tab [#the-hermes-tab] A scratchpad for plain JavaScript on Hermes: edit code, it compiles to bytecode, and you can call any global function with JSON arguments and time repeated calls. Useful for checking whether a piece of logic is fast on Hermes before you put it in a component. # Embedding cost (/docs/guides/embedding-cost) BakeNative is meant to go into an app that already exists, as one screen. This page measures what that screen costs the host app. The screen is the Starter app (`examples/app`): an app bar with a five-way switcher, a counter button, a logo, a title, a paragraph and four cards. For comparison, the same screen is also written natively in UIKit, AppKit and SwiftUI (`examples/ios-brownfield/App/NativeStarter.swift`, `examples/mac-brownfield/Sources/ShellKit/Starter.swift`). The native versions show the logo as an SF Symbol, because a native app ships its logo as an image rather than SVG path data. The hosts: - **iOS:** `examples/ios-brownfield`, a UIKit app with a `UINavigationController`. The BakeNative screen is an `BakeNativeViewController` pushed with the normal animated push, from the catalog's row selection. - **macOS:** `examples/mac-brownfield`, an AppKit app with one 640×480 window. Opening a screen swaps its view controller in as the window's content, which is the AppKit equivalent of a push. The BakeNative screen is an `BakeNativeView`. `MacShell` is the same app without BakeNative. The iOS numbers below come from the **simulator** on a Mac, not from a phone. Simulator timings depend on the Mac and are not what users see. The device row is still to be measured. ## What is measured [#what-is-measured] - **First frame:** from the open to the display refresh that shows the screen's content. On iOS the open is the row selection. On macOS it is the moment before the screen's view controller is created. The end is the first display refresh after the Core Animation commit that carries the content. It is computed from the display link's phase and period, so a callback delivered late does not move it. - **iOS:** that commit is the push transaction's commit when the content is in it, which is the case for native screens and for a BakeNative screen drawn from a frame. For a first mount from JavaScript it is the first commit that has the BakeNative views. - **macOS:** it is the end of the first main run loop turn after which the screen's whole view tree is laid out, displayed and layer-backed. AppKit displays a new view in its own display cycle, after Core Animation's commit observer. - **Interactive:** for BakeNative, the screen is adopted (snapshot views kept, JavaScript handlers attached) or mounted. Native screens take input from their first frame, so for them interactive equals first frame. - **Views created on adopt:** how many native views the adoption had to create. It should be 0: the first frame's views are kept as they are. - **Binary size:** the same minimal app built twice, without and with BakeNative plus one screen. On iOS that is `SizeShell` and `SizeShellBakeNative`; on macOS, `MacShell` and `MacBrownfield`. Release builds. The executable is measured after `strip -S -x`, the way an archive ships it. - **Memory:** `phys_footprint` (what jetsam and Activity Monitor count). One process per screen type, 10 open/close cycles, measured before the first open, while the screen is shown, and 2 s after each close. Every timing is the median and p90 of at least 30 samples. A sample counts only while the Mac is quiet. The default rule is a 15-minute load average below 40. These results used a quiet-window rule instead: the 1-minute load below 30 for two minutes before measuring, and below 30 at every sample. - **Cold** samples are the first open after launching a fresh process, one sample per process. - **Repeat** samples come from one process that opens and closes the screens over and over, interleaved, after warm-up opens. On iOS, the cold BakeNative open is measured twice: once with the frame cache emptied (the first mount, from JavaScript), once with it kept (the frame from the device cache). The cold UIKit and SwiftUI screens are measured the same way. The repeat runs measure BakeNative with and without a prewarm. ## Results [#results] ### iOS simulator: first push after launch (a fresh process per sample) [#ios-simulator-first-push-after-launch-a-fresh-process-per-sample] Simulator iPhone19,4, 2026-11-26; load at the samples: 1-minute 4.8–19.2, 15-minute 15.4–24.3; 0 samples dropped (1-minute load >= 30). | Screen | N | First frame (median / p90 ms) | Interactive (median / p90 ms) | Views created on adopt | | --- | --- | --- | --- | --- | | BakeNative Starter: adopted, prewarm off | 30 | 100.8 / 127.6 | 100.0 / 127.1 | 0 (max of 30) | | BakeNative Starter: mounted, prewarm off | 30 | 104.4 / 120.0 | 104.3 / 124.6 | – | | SwiftUI Starter | 30 | 139.7 / 172.7 | 139.7 / 172.7 | – | | UIKit Starter | 30 | 113.3 / 138.2 | 113.3 / 138.2 | – | ### iOS simulator: repeat push in one process (frame cache hit) [#ios-simulator-repeat-push-in-one-process-frame-cache-hit] Simulator iPhone19,4, 2026-11-26; load at the samples: 1-minute 8.8–19.7, 15-minute 64.4–81.6; 0 samples dropped (1-minute load >= 30). | Screen | N | First frame (median / p90 ms) | Interactive (median / p90 ms) | Views created on adopt | | --- | --- | --- | --- | --- | | BakeNative Starter: adopted, prewarm off | 30 | 32.7 / 45.9 | 32.3 / 44.5 | 0 (max of 30) | | BakeNative Starter: adopted, prewarm on (hit) | 30 | 35.3 / 44.0 | 33.4 / 42.8 | 0 (max of 30) | | SwiftUI Starter | 30 | 37.3 / 53.3 | 37.3 / 53.3 | – | | UIKit blank screen (floor) | 30 | 31.1 / 36.2 | 31.1 / 36.2 | – | | UIKit Starter | 30 | 42.8 / 50.7 | 42.8 / 50.7 | – | ### macOS: first open after launch (a fresh process per sample) [#macos-first-open-after-launch-a-fresh-process-per-sample] arm64, Version 27.0.1 (Build 26A434), 100 Hz; 2026-11-26; load at the samples: 1-minute 10.2–17.0, 15-minute 26.0–33.6; 0 samples dropped (1-minute load >= 30); 0 occluded or timed out. | Screen | N | First frame (median / p90 ms) | Interactive (median / p90 ms) | Views created on adopt | | --- | --- | --- | --- | --- | | AppKit Starter | 30 | 37.8 / 47.4 | 37.7 / 47.2 | – | | BakeNative Starter: adopted, prewarm off | 30 | 35.4 / 39.2 | 35.5 / 38.9 | 0 (max of 30) | | BakeNative Starter: adopted, prewarm on (hit) | 30 | 28.9 / 36.2 | 25.5 / 31.1 | 0 (max of 30) | | SwiftUI Starter | 30 | 60.2 / 65.1 | 60.2 / 65.0 | – | ### macOS: repeat open in one process [#macos-repeat-open-in-one-process] arm64, Version 27.0.1 (Build 26A434), 100 Hz; 2026-11-26; load at the samples: 1-minute 12.7–17.8, 15-minute 44.0–53.9; 0 samples dropped (1-minute load >= 30); 0 occluded or timed out. | Screen | N | First frame (median / p90 ms) | Interactive (median / p90 ms) | Views created on adopt | | --- | --- | --- | --- | --- | | AppKit Starter | 30 | 29.6 / 31.9 | 29.6 / 31.9 | – | | BakeNative Starter: adopted, prewarm off | 30 | 20.0 / 22.7 | 16.5 / 20.1 | 0 (max of 30) | | BakeNative Starter: adopted, prewarm on (hit) | 30 | 16.4 / 23.0 | 16.5 / 18.3 | 0 (max of 30) | | SwiftUI Starter | 30 | 26.2 / 38.6 | 26.2 / 38.6 | – | Adopted samples in the timing tables: 210, views created on adopt: max 0. ### iOS simulator: memory (phys_footprint, MB) [#ios-simulator-memory-phys_footprint-mb] | Screen | Processes × cycles | Idle | Before first open | Shown (median; vs idle) | After close, cycle 1 | After close, last cycle (vs idle) | | --- | --- | --- | --- | --- | --- | --- | | UIKit Starter | 1 × 10 | 25.3 | 25.3 | 32.0 (+6.8) | 29.4 | 32.7 (+7.5) | | SwiftUI Starter | 1 × 10 | 25.8 | 25.6 | 31.8 (+6.1) | 30.6 | 31.7 (+5.9) | | BakeNative Starter, prewarm off | 1 × 10 | 25.5 | 25.5 | 36.3 (+10.8) | 29.0 | 34.0 (+8.5) | | BakeNative Starter, prewarm on | 1 × 10 | 26.5 | 27.3 | 37.1 (+10.7) | 33.6 | 34.4 (+8.0) | ### macOS: memory (phys_footprint, MB) [#macos-memory-phys_footprint-mb] | Screen | Processes × cycles | Idle | Before first open | Shown (median; vs idle) | After close, cycle 1 | After close, last cycle (vs idle) | | --- | --- | --- | --- | --- | --- | --- | | AppKit Starter (MacShell) | 1 × 10 | 17.5 | 17.5 | 20.3 (+2.9) | 20.6 | 19.9 (+2.4) | | SwiftUI Starter (MacShell) | 1 × 10 | 16.7 | 16.7 | 24.5 (+7.8) | 23.9 | 23.9 (+7.2) | | BakeNative Starter, prewarm off (MacBrownfield) | 1 × 10 | 17.1 | 17.1 | 24.6 (+7.5) | 22.3 | 22.7 (+5.6) | | BakeNative Starter, prewarm on (MacBrownfield) | 1 × 10 | 17.3 | 19.8 | 25.1 (+7.8) | 22.5 | 22.4 (+5.2) | ### iOS: binary size (Release, unsigned) [#ios-binary-size-release-unsigned] | | Device (arm64) | Simulator (arm64) | | --- | --- | --- | | Executable, stripped (`strip -S -x`) | 0.14 → 3.65 MB (+3.52) | 0.12 → 3.65 MB (+3.53) | | hermesvm.framework (embedded, as shipped) | +3.62 MB | +3.62 MB | | One Octane screen (`app.hbc` + `app.css` + manifest) | +0.34 MB | +0.34 MB | | .app, executable stripped | 0.14 → 7.61 MB (**+7.48**) | 0.12 → 7.61 MB (**+7.48**) | | .app as zip -9 (≈ compressed download) | 0.05 → 3.32 MB (+3.27) | 0.05 → 3.39 MB (+3.34) | ### macOS: binary size (release, arm64) [#macos-binary-size-release-arm64] | | MacShell → MacBrownfield | | --- | --- | | Executable, stripped (`strip -S -x`) | 0.19 → 3.75 MB (+3.56) | | hermesvm.framework (embedded) | +4.33 MB | | Resources (one Octane screen with its baked `app.baked`) | +0.39 MB | | .app, executable stripped | 0.19 → 8.47 MB (**+8.28**) | | .app as zip -9 | 0.09 → 3.65 MB (+3.56) | ### Reading the results [#reading-the-results] - **Adoption created no views.** Every adopted sample in the timing tables reported `viewsCreatedOnAdopt` = 0 (the count line above the memory tables). - **iOS, first push after launch.** Two cases ran: - **mounted:** the frame cache was emptied, so the screen mounts from JavaScript; - **adopted:** a fresh process with the frame cache on disk. On the simulator, both BakeNative cases and the UIKit and SwiftUI screens fall between about 100 and 140 ms. The native screens pay the same first-push cost. - **iOS, repeat push.** The cached BakeNative screen opens within about 2 ms of the blank UIKit screen, which is the floor of a push. With a prewarm that hits, it was no faster on the simulator (35.3 vs 32.7 ms median). - **The iOS native rows rest on an assumption.** The UIKit and SwiftUI rows assume the content is in the push transaction's commit. Verifying that is the [first gap](#gaps). The macOS rows check it. - **iOS prewarm in a fresh process.** For the first push after launch, `BakeNativeBundle.prewarm` prepared nothing in this run. No viewport had been learned yet, so the prewarm estimated 382×600 under a standard navigation bar, but the screen opened at 382×562 under the catalog's large title (`ios-sim-memory.json`, the first cycle of the prewarm-on process: `prewarmStage` nil, `prewarmEstimate`, `viewEnvironment`). The estimate missed the frame cache slot, and this bundle ships no `app.baked`. From the second push on, the learned size matched and the prewarm hit. The prewarm now takes the size from the slot an earlier launch cached, or from the navigation bar as it is, so the first push of a new process hits too. These tables predate that change. - **Memory does not return to the level before the first push. It plateaus.** - **iOS (simulator):** after the last close, BakeNative sits +8.5 MB above idle, against +7.5 MB for UIKit and +5.9 MB for SwiftUI. - **macOS:** after the last close, BakeNative sits +5.6 MB above idle, against +2.4 MB for AppKit and +7.2 MB for SwiftUI. - **Over 10 cycles:** the after-close value is flat on macOS. On iOS, UIKit and BakeNative each step up once at the 5th cycle (+2.3 and +4.7 MB), in separate processes, then stay flat. The cause of that step was not identified and may come from the harness. Only one process per row was measured. - **Prewarm rows:** their "before first open" value includes the prepared screen, so compare against idle. - **Linking BakeNative (macOS):** it does not change idle memory. The idle footprint is about the same in `MacShell` and `MacBrownfield` (16.7–17.5 MB). On iOS this was not measured: every iOS row runs in the one app that links BakeNative. - **Load.** These ran in a quiet window: every sample was taken with the 1-minute load below 30. The 15-minute average was still coming down from an earlier busy period: 44–82 during the repeat runs and 15–34 during the cold runs. ### Gaps [#gaps] - On iOS, whether the native screens' content is in the push commit is not verified. The macOS layer check was not ported to iOS. - iOS cold opens were not run with a prewarm (when these ran, the first prewarm of a process prepared nothing, see above), and the cold blank-screen floor was not run either. - Memory was measured with one process per row instead of three. - iOS idle footprint without BakeNative linked was not measured. - The device row below is empty. ### Device [#device] | | First frame | Interactive | Memory | | --- | --- | --- | --- | | iPhone (device) | to be measured | to be measured | to be measured | ## Reproduce [#reproduce] ```sh tools/build-rust-apple.sh && examples/ios-brownfield/build-octane.sh # Sizes (no simulator needed) tools/embed-cost/ios-size.sh examples/mac-brownfield/build.sh && examples/mac-brownfield/package-app.sh node tools/embed-cost/mac-size.mjs # macOS timings and memory # (--load-1m 30 --sustain 120: the quiet-window rule used here; default: 15-minute load < 40) node tools/embed-cost/mac-trace.mjs cold --load-1m 30 node tools/embed-cost/mac-trace.mjs warm --load-1m 30 node tools/embed-cost/mac-trace.mjs memory --reps 1 --load-1m 30 # iOS simulator: Release build with the trace's Core Animation phases, then each mode xcodebuild -project examples/ios-brownfield/iOSBrownfield.xcodeproj -scheme iOSBrownfield \ -configuration Release -destination 'generic/platform=iOS Simulator' \ -derivedDataPath examples/ios-brownfield/build/trace \ "SWIFT_ACTIVE_COMPILATION_CONDITIONS=\$(inherited) BAKE_OPEN_TRACE" build node tools/embed-cost/ios-trace.mjs cold --udid --cells 0,2,4,5 --load-1m 30 node tools/embed-cost/ios-trace.mjs warm --udid --load-1m 30 node tools/embed-cost/ios-trace.mjs memory --udid --reps 1 --load-1m 30 node tools/embed-cost/report.mjs # the tables above (each file's own load rule) ``` The raw results are in `docs/data/embedding-cost/`. Every sample there includes the load average, the launch phase, the prewarm outcome and the open's timeline. # Where a feature lives (/docs/guides/feature-tiers) Every native feature an Octane app uses belongs to exactly one tier. The tier decides who owns the code, how it reaches the app, and how the app registers it. Decide the tier before you write any code. | Tier | Examples | Who owns the code | How the app gets it | | --- | --- | --- | --- | | [Built-in](#built-in) | `fetch`, ``, `