Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The README introduces WebFront through the Game of Life walkthrough, demonstrati

## Repository map

- `include/webfront/`: public header-only library, included as `<webfront/...>`. `WebFront.hpp` is the main orchestration API; `Commands.hpp` adds an application's C++ commands to the developer environment's terminal.
- `include/webfront/`: public header-only library, included as `<webfront/...>`. `WebFront.hpp` is the main orchestration API; `Bridge.hpp` is the light header of the units that only use the bridge (ADR-029: never include the server, the networking or stdexec from it; `BridgeHost.hpp` stays equivalent to `JsFunction` and to `cppFunction`'s registration); `Commands.hpp` adds an application's C++ commands to the developer environment's terminal.
- `include/webfront/components/react/`: optional C++ snapshot stores coalesced per browser; the React adapter is installed separately with `wf` and documented in `docs/REACT.md`.
- `include/webfront/components/forms/`: optional type descriptors (C++23), forms, inspectors and TypeScript declarations generated from them, and an optional C++26 reflection layer (`Reflection.hpp`, GCC 16 only) documented in `docs/FORMS.md`.
- `include/webfront/http/`: HTTP and WebSocket protocol implementation.
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,20 @@ target_link_libraries(MyApp PRIVATE WebFront::WebFront)

As a subproject, examples and tests are off by default and compiler settings do not leak into your targets. `WEBFRONT_BUILD_EXAMPLES=OFF` disables examples in a standalone build too.

`WebFront.hpp` is slow to compile. A unit that only registers C++ functions or calls JavaScript can include the light `webfront/Bridge.hpp` instead, and receives `webfront::bridgeFunctions(app)` or `webfront::bridgeUI(ui)` from the unit that creates the application ([ADR-029](docs/adr/ADR-029-en-tete-leger-du-bridge.md), [measurements](docs/BUILD_TIME_STUDY.md)):

```cpp
#include <webfront/Bridge.hpp>

void registerFunctions(webfront::BridgeFunctions& functions) {
functions.cppFunction("greet", [](webfront::BridgeUI browser, const std::string& name) {
browser.jsFunction("print")("hello " + name);
});
}
```

Its callbacks answer at once: register senders, coroutines and streams on the application.

An installed WebFront (`cmake --install`, the vcpkg overlay port or the Conan recipe) is used with `find_package(WebFront CONFIG REQUIRED)`. [Distributing an application](docs/DISTRIBUTION.md) covers it, installers (`webfront_package()`), the bill of materials and verified updates.

<details>
Expand Down
42 changes: 34 additions & 8 deletions docs/BUILD_TIME_STUDY.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,40 @@ The rows overlap: they cannot be added.
- **`<regex>`** was included by `HTTPServer.hpp` and used nowhere. The include is removed; the effect on `HelloWorld.cpp`
is within the noise (32.9 s and 33.5 s).
- **The development components** (inspectors, introspection) do not change the cost measurably in a minimal application.
- **A lighter header** is not delivered. A second unit under 5 s would have to avoid `WebLink.hpp` (5.1 s for the front end
alone), which `UI`, `cppFunction` and `jsFunction` are templates over: it needs a type-erased boundary between an
application unit and the units that use it, a change of the public design rather than of the includes.
- **`import webfront;`** (a module whose global module fragment includes `WebFront.hpp`) is not adopted: GCC 16.1 stops
with an internal compiler error (segmentation fault, `stdexec/__detail/__query.hpp`). Clang and MSVC were not tried; a
module is not worth offering until the three compilers of the CI build it.

No MSVC figure was taken for this study: the target of 30 % less on `HelloWorld.cpp` with MSVC remains open.
- **A lighter header** is delivered: `webfront/Bridge.hpp`, below.
- **`import webfront;`** (a module whose global module fragment includes `WebFront.hpp`) is not adopted. Tried again with
the light header: GCC 16.1 still ends with an internal compiler error (`stdexec/__detail/__query.hpp`), and Clang 22
precompiles a module whose import then fails to compile in stdexec (`no matching function for call` from
`__detail/__storage.hpp`). MSVC was not tried.

## The light header (#766, ADR-029)

A unit that only registers C++ functions or calls JavaScript includes `webfront/Bridge.hpp` and takes a
`webfront::BridgeFunctions` or a `webfront::BridgeUI`; the unit that includes `WebFront.hpp` makes them with
`webfront::bridgeFunctions(app)` and `webfront::bridgeUI(ui)`.

Same machine, GCC 16.1, medians of three runs, no compiler cache, while the machine had some other load (average 4 to 12
on 24 threads).

| What is compiled | `-O3 -DNDEBUG` | `-O0` | Peak memory (`-O3`) |
| --- | --- | --- | --- |
| A second unit that calls `ui.jsFunction`, with `WebFront.hpp` | 17.8 s | 11.8 s | 1.1 GB |
| The same with `Bridge.hpp` | 2.3 s | 1.9 s | 0.33 GB |
| `test/unit/BridgeLightPage.cpp`: eight functions, two JavaScript calls | 5.4 s | 3.2 s | 0.42 GB |
| `Bridge.hpp` alone, `-fsyntax-only` | 1.8 s | | 0.29 GB |
| `HelloWorld.cpp` before the change | 35.6 s | | 1.4 GB |
| `HelloWorld.cpp` after the change | 32.8 s | | 1.4 GB |

- The target of a secondary application unit under 5 s with GCC is met for a unit that calls JavaScript. A unit pays for
each signature it instantiates: eight registrations are at 5.4 s with optimisation.
- **`HelloWorld.cpp` does not get cheaper**: the difference above is within the noise. It instantiates the application,
which `Bridge.hpp` does not touch. The target of 30 % less on `HelloWorld.cpp` is **not met**, and no MSVC figure was
taken (no MSVC on the machine that made these measurements).
- Clang 22 `-ftime-trace` on `HelloWorld.cpp` (38 s): 17.5 s front end and 20.4 s back end. The largest instantiations,
which overlap, are `webfront::BasicWF` (12.5 s) and `webfront::http::Server` (8.5 s), then the senders of stdexec.
Reducing it means instantiating less of the server and the application, or compiling them once, which a header-only
core does not do (ADR-001).
- `<regex>` is no longer included anywhere under `include/`: nothing is left to rewrite by hand.

## Run time

Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ these entries stays in the GitHub releases and the Git history.
- A type that converts to `std::string_view` without being a string is no longer written as text by `info()`, `fail()` and `checkEqual` (it appears as `{?}` without a `Printer`): specialize `webfront::bdd::isString` (or `Printer`) for it (#739, `docs/BDD.md`).

### Added
- A unit that only registers C++ functions or calls JavaScript can include the light `webfront/Bridge.hpp` and compiles in about a third of the time: pass it `webfront::bridgeFunctions(app)` or `webfront::bridgeUI(ui)` (#766, ADR-029).
- Bundle npm packages that use `#` subpath imports (the `imports` of their `package.json`, naming their own files or a dependency), such as Svelte 5, once an environment with it is published (#767).
- Start an interface without a UI library on a C++ state store with `wf create store`, once an environment with it is published (#767, `docs/STORE.md`).
- `@webfront/store` adapters for Vue and Lit are run in the browser suite, and the Svelte store contract with `svelte/store` 5 in a `wf test` case, with a per-library support policy (#767, ADR-010).
Expand Down
62 changes: 62 additions & 0 deletions docs/adr/ADR-029-en-tete-leger-du-bridge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# ADR-029 : Un en-tête léger pour les unités qui n'utilisent que le bridge

## Versions

| Version | Date | État | Auteur | Évolution | Révision Git |
| --- | --- | --- | --- | --- | --- |
| 1.0 | 2026-12-05 | Proposée | Ambroise Leclerc | `webfront/Bridge.hpp` : frontière à effacement de type entre l'unité qui instancie l'application et les autres (#766). | Branche `766-light-header` |

## État et chronologie

**Proposée.** Décision initiale : **2026-12-05** (version 1.0).

## Contexte

Une unité qui ne fait qu'enregistrer des fonctions C++ ou appeler JavaScript devait inclure `WebFront.hpp` : le serveur,
le réseau, stdexec et les inspecteurs, soit 15,7 s avec GCC 16 en `-O3` (`BUILD_TIME_STUDY.md`). `UI`, `cppFunction` et
`jsFunction` sont des gabarits sur le type de l'application, qu'aucun réagencement d'inclusions ne retire de ces unités.

## Décision

`webfront/Bridge.hpp` donne à ces unités `BridgeUI` et `BridgeFunctions`, sans le type de l'application :

- la frontière est `detail::BridgeTarget` (un navigateur) et `detail::BridgeRegistrar` (un enregistrement), des
interfaces virtuelles par lesquelles passent des messages binaires entiers ;
- l'encodage et le décodage des valeurs restent des gabarits, instanciés dans l'unité qui connaît les types, avec les
codecs de `weblink/Messages.hpp` : le format du bridge ne change pas ;
- l'unité qui inclut `WebFront.hpp` instancie l'application et donne les objets légers avec `webfront::bridgeUI(ui)` et
`webfront::bridgeFunctions(app)` ;
- `Bridge.hpp` n'inclut ni le serveur, ni le réseau, ni stdexec, ni les watches ; la construction de la seconde unité des
tests le vérifie pour stdexec.

Une fonction enregistrée ainsi est une fonction de l'application : mêmes noms réservés, mêmes exigences d'appelant,
mêmes comptes et mêmes déclarations TypeScript pour les inspecteurs et `wf bindings`.

## Options écartées et motifs

- En-têtes précompilés et `extern template` : mesurés et écartés (`BUILD_TIME_STUDY.md`).
- Faire de `UI` et `cppFunction` eux-mêmes des types effacés : chaque appel de toute application paierait une indirection
et les fonctions différées devraient aussi être effacées.
- `import webfront;` : GCC 16.1 se termine par une erreur interne sur stdexec.

## Conséquences

- **Bénéfice :** une unité secondaire ne paie plus le serveur ni stdexec.
- **Coût :** une indirection virtuelle et une copie du message par appel passé par `Bridge.hpp`.
- **Limites :** pas de rappel différé (sender, coroutine, `Stream`), pas de `jsFunctionSender`, pas d'enregistrement sur un
espace (`Space`) ; ces cas restent dans une unité qui inclut `WebFront.hpp`. Un `BridgeUI` ou un `BridgeFunctions` ne
doit pas survivre à son application. Une politique de tampons autre que la politique par défaut s'écrit
`BasicBridgeUI<Policy>` dans l'unité légère.

## Prescriptions d'implémentation et de génération de code

- Ne rien inclure dans `Bridge.hpp` qui tire le réseau ou stdexec ; mesurer avant d'y ajouter un en-tête.
- Garder `BridgeHost` équivalent à `JsFunction` et à l'enregistrement de `cppFunction` : une règle ajoutée à l'un vaut
pour l'autre.
- Ne pas présenter `Bridge.hpp` comme réduisant le coût de l'unité qui instancie l'application.

## Sources et vérification

`include/webfront/Bridge.hpp`, `include/webfront/BridgeHost.hpp` ; `test/unit/BridgeLightPage.cpp` et
`BridgeLightTests.cpp`, `test/web/suite/specs/light-bridge-specs.mjs`, `test/cmake/consumer/` ; mesures dans
`docs/BUILD_TIME_STUDY.md`.
5 changes: 3 additions & 2 deletions docs/adr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ verification evidence remain in [PROJECT_STATUS](../PROJECT_STATUS.md).
| [ADR-026](ADR-026-configuration-mcp-persistante.md) | Stable MCP client configuration with explicit development security modes | Accepted | 2026-11-22 | 1.2 — 2026-11-22 |
| [ADR-027](ADR-027-inspecteurs-de-l-etat-de-l-application.md) | Application state inspectors in the developer environment only: reserved `webfront.inspector.*` functions refused to unproven views unless the application trusts loopback clients, tree nodes on existing bridge types with paged reads and paged differences, observer operations run whole under the application's lock or on its executor, writes only when the application provides them, one `inspector.html` page, shown in a floating window of the page and, for a detached panel only, in the first container that grants access (a native secondary window, else a system-browser tab); an introspectable registry of the registered C++ functions, of the JavaScript functions C++ calls and of the connected browsers, counted with relaxed atomics and timed only while an inspector reads | Accepted through 1.6; 1.7 proposed | 2026-11-25 | 1.7 — 2026-12-04 |
| [ADR-028](ADR-028-distribution.md) | Distributing an application without imposing a tool, a key or a server: an installed CMake package with a vcpkg overlay port and a Conan recipe, CPack installers (Debian, disk image, NSIS) signed only by the application's command, an SPDX bill of materials, and an optional updater verifying ECDSA P-256 with the system's cryptography before a swap with rollback | Accepted | 2026-12-05 | 2.0 — 2026-12-05 |
| [ADR-029](ADR-029-en-tete-leger-du-bridge.md) | A light header for the units that only use the bridge: a type-erased boundary to the unit that instantiates the application | Proposed | 2026-12-05 | 1.0 — 2026-12-05 |

Numbering follows the reading topics; milestones and individual file histories provide
the chronology, which does not follow the numerical order.
Expand All @@ -88,7 +89,7 @@ the chronology, which does not follow the numerical order.

| Planned work | ADRs to read in addition to the 001/002/012 baseline |
| --- | --- |
| Bridge, codecs or new data types | 003, 004, 006, 009 |
| Bridge, codecs or new data types | 003, 004, 006, 009, 029 |
| Networking, concurrency, lifetimes or shutdown | 005, 006 |
| Files, resources and modules | 009, 010 |
| A new engine or changes to window lifecycle | 006, 007, 008 |
Expand Down Expand Up @@ -117,7 +118,7 @@ Do not replace historical dates with the date of an editorial change to the docu
Keep previous rows and update the current version in the index.

- Use one `ADR-NNN-description.md` file per decision and one row in this index. The next number
is **ADR-029**. Retain historical numbers and files.
is **ADR-030**. Retain historical numbers and files.
- For a new decision that has not been integrated, use **Proposée** (Proposed), its actual
proposal date and validation criteria; do not assign an artificial historical commit date.
- After integration, record the date and supporting commits, the accepted negative
Expand Down
Loading
Loading