Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
scripted_ui_prewarm.hpp
Go to the documentation of this file.
1#pragma once
2
3// Background preparation of a scripted editor's process-wide caches, so the
4// host's view-creation call does not pay for the first parse of the UI.
5//
6// A hosted editor mounts its document inside the host's view-creation call
7// (content-first open), and the first open in a process pays one-time costs
8// there: QuickJS compiling the UI runtime and every inline script of a
9// materialized document, and the decode + SHA-256 verification of that
10// document. Both results are already kept process-wide (the script bytecode
11// cache and the materialized document cache), so a plug-in can produce them
12// before an editor is requested -- typically from its constructor, which a
13// host runs when it instantiates the plug-in -- on a background thread that
14// never touches a realm, a view or the audio thread.
15//
16// What it does NOT do: build views, run any script, or keep a realm alive.
17// The per-open work (evaluating the runtime, laying out the tree, the first
18// GPU frame) still happens in the view-creation call.
19
20#include <atomic>
21#include <chrono>
22#include <cstdint>
23#include <string>
24#include <vector>
25
26namespace pulp::view {
27
35 std::vector<std::string> scripts;
40 std::vector<std::string> materialized_documents;
41};
42
54
62inline std::atomic<ScriptedUiPrewarmRunner>& scripted_ui_prewarm_runner() noexcept {
63 static std::atomic<ScriptedUiPrewarmRunner> runner{nullptr};
64 return runner;
65}
66
68 std::uint64_t requests = 0;
69 std::uint64_t scripts_compiled = 0;
70 std::uint64_t documents_verified = 0;
71 std::uint64_t documents_rejected = 0;
72 bool idle = true;
73};
75
78bool wait_for_scripted_ui_prewarm(std::chrono::milliseconds timeout);
79
80} // namespace pulp::view
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
ScriptedUiPrewarmStats scripted_ui_prewarm_stats()
std::atomic< ScriptedUiPrewarmRunner > & scripted_ui_prewarm_runner() noexcept
Definition scripted_ui_prewarm.hpp:62
void(*)(ScriptedUiPrewarmRequest) ScriptedUiPrewarmRunner
prewarm_scripted_ui(), reachable without naming it.
Definition scripted_ui_prewarm.hpp:61
bool wait_for_scripted_ui_prewarm(std::chrono::milliseconds timeout)
Block until the worker is idle or timeout passes; true when idle.
void prewarm_scripted_ui(ScriptedUiPrewarmRequest request)
Queue request for the process's prewarm worker and return at once.
Definition scripted_ui_prewarm.hpp:28
std::vector< std::string > materialized_documents
Inputs the editor passes to __pulpRuntimeImport__(text, 'materialized-browser'), byte-identical.
Definition scripted_ui_prewarm.hpp:40
std::vector< std::string > scripts
Scripts the editor loads through WidgetBridge::load_script() (a ScriptedUiSession's script file,...
Definition scripted_ui_prewarm.hpp:35
Definition scripted_ui_prewarm.hpp:67
std::uint64_t documents_rejected
documents that failed verification
Definition scripted_ui_prewarm.hpp:71
std::uint64_t scripts_compiled
scripts this worker compiled
Definition scripted_ui_prewarm.hpp:69
std::uint64_t documents_verified
documents this worker decoded
Definition scripted_ui_prewarm.hpp:70
std::uint64_t requests
requests accepted
Definition scripted_ui_prewarm.hpp:68
bool idle
nothing queued or running
Definition scripted_ui_prewarm.hpp:72