Skip to content

[embedder] Add FlutterEngineSpawn API for engine group spawning - #52

Draft
xiaowei-guan wants to merge 6 commits into
flutter-tizen:flutter-3.47.5from
xiaowei-guan:flutter-3.47.5-engine-group-02
Draft

xiaowei-guan wants to merge 6 commits into
flutter-tizen:flutter-3.47.5from
xiaowei-guan:flutter-3.47.5-engine-group-02

Conversation

@xiaowei-guan

Copy link
Copy Markdown

Why spawn engines?

Android and iOS already have engine groups (FlutterEngineGroup): additional
engines spawned from a running one share its Dart VM, isolate snapshot, and
isolate group heap — far cheaper than independent engines. The C embedder API
has no equivalent, so embedders needing multiple Flutter UIs in one process
must pay full VM + snapshot + thread cost per engine — impractical on
memory-constrained devices like Smart TVs, and too slow for instantly-appearing
UIs.

The shell already implements spawning internally (Shell::Spawn); it is just
not exposed. This PR adds FlutterEngineSpawn to embedder.h:

  • Less memory — spawns share the parent's VM, snapshot, and isolate group heap.
  • Faster startup — no VM init, no snapshot load, no new threads; the spawn
    is returned already running its Dart entrypoint.
  • Cheap Dart cooperation — isolates in one group exchange messages without
    cross-group overhead.

Use cases

  • Multi-view UIs on one device (primary target): TV home screens with
    several live surfaces — app cards, previews, PiP — each with its own Flutter
    UI tree, all sharing one VM. Tizen TV multi-view support is built on this
    API (follow-ups: TizenEngineGroup + per-view pixel-buffer render targets).
  • Instant auxiliary UIs: overlays, settings panes, on-screen keyboards,
    splash screens that must appear immediately.
  • Independent mini-apps from one kernel snapshot: dashboards/app grids
    where each cell runs a separate dart_entrypoint with its own route/args.
  • Companion worker engines in the same isolate group for cheap UI↔worker
    data exchange.

Add FlutterSpawnConfig and FlutterEngineSpawn to the public embedder API and proc table. Spawn a running child engine in the parent isolate group while reusing its threads, VM, snapshots, renderer configuration, and platform callbacks. Support custom entrypoints, arguments, routes, and per-spawn user data. Preserve output handles on failure, initialize spawned rendering surfaces, and respect FLUTTER_ENGINE_NO_PROTOTYPES.
Cover default and nested spawning, custom entrypoints, entrypoint arguments, initial routes, callback user data, lifecycle contracts, rendering, shared thread hosts, error paths, and proc-table exposure.
Add regression coverage for Vulkan extension names, extension pointer arrays, and pipeline cache path ownership after the embedder releases the original inputs.
Own Vulkan strings and pointer arrays retained for spawning, respect struct_size when reading the cache path, polish configuration handling, and document that root isolate startup and callbacks may occur before FlutterEngineSpawn returns or populates engine_out.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T13:18:07.627640Z 5de1a68 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@xiaowei-guan
xiaowei-guan marked this pull request as draft November 23, 2026 13:03

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5de1a6829e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@xiaowei-guan
xiaowei-guan force-pushed the flutter-3.47.5-engine-group-02 branch from 5de1a68 to 1b09615 Compare November 24, 2026 06:12
Add regression coverage for flushing parent and child microtasks through a shared custom UI task runner and for retaining only fields advertised by older renderer configurations.
Flush all engines sharing a custom UI task runner, preserve shared runners during child shutdown, and copy only renderer fields advertised by the active struct_size to support older embedders safely.
@xiaowei-guan
xiaowei-guan force-pushed the flutter-3.47.5-engine-group-02 branch from 1b09615 to 78cb454 Compare November 24, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant