Возможность предварительной компиляции скрипта для ускорения запуска
Хочу попробовать сделать свою версию #1554 с прекомпиляцией скриптов. Только не автоматическую, а ручную WIP, пока в исследовательских целях)
Summary by CodeRabbit
-
New Features
- Added script precompilation via a new command-line option to produce .osc precompiled scripts.
- Added execution support for precompiled .osc scripts for faster load/startup.
- Added ability to persist and restore compiled modules to disk, improving repeatable deployments and tooling.
✏️ Tip: You can customize this high-level summary in your review settings.
[!IMPORTANT]
Review skipped
Draft detected.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.
Walkthrough
Adds MessagePack dependency and module persistence for precompiled runtime modules, a ModuleSerializer for save/load, a CLI "-build" behavior to emit .osc files, a build behavior that compiles and saves modules, an engine overload to create processes from IExecutableModule, and ExecuteScriptBehavior branching to load .osc or source.
Changes
| Cohort / File(s) | Summary |
|---|---|
Dependency Configurationsrc/OneScript.Core/OneScript.Core.csproj |
Added MessagePack v3.1.4 PackageReference for serialization support. |
Module Serialization Infrastructuresrc/ScriptEngine/Machine/PrecompiledRuntimeModule.cs |
Added PrecompiledRuntimeModule (MessagePack-annotated, implements IExecutableModule) and ModuleSerializer with SaveModule() and LoadModule() to persist modules as MessagePack bytes. |
Script Engine Integrationsrc/ScriptEngine.HostedScript/HostedScriptEngine.cs |
Added public Process CreateProcess(IHostApplication host, IExecutableModule module) overload to initialize engine and create a process directly from an executable module. |
CLI Option Registrationsrc/oscript/BehaviorSelector.cs |
Registered "-build" command-line option mapped to BuildPrecompiledBehavior.Create. |
Build Behaviorsrc/oscript/BuildPrecompiledBehavior.cs |
Added BuildPrecompiledBehavior class: compiles source to IExecutableModule, calls ModuleSerializer.SaveModule() to write .osc, returns exit codes and prints ScriptException messages. |
Execution Logicsrc/oscript/ExecuteScriptBehavior.cs |
Modified to detect .osc files (case-insensitive): load via ModuleSerializer.LoadModule() and create process from module; otherwise load source and create process from source; each path has its own error handling. |
Sequence Diagram
sequenceDiagram
participant User
participant CLI as BehaviorSelector
participant Build as BuildPrecompiledBehavior
participant Hosted as HostedScriptEngine
participant Serializer as ModuleSerializer
participant Disk
rect rgb(220, 240, 255)
note over User,CLI: Build flow (-build)
User->>CLI: invoke -build script.os
CLI->>Build: Create & Execute
Build->>Hosted: Load source from file
Build->>Hosted: Compile -> IExecutableModule
Build->>Serializer: SaveModule(module, script.osc)
Serializer->>Disk: write MessagePack bytes
Build-->>User: exit code (0/1)
end
rect rgb(255, 235, 220)
note over User,CLI: Execute flow (script.osc)
User->>CLI: run script.osc
CLI->>Hosted: ExecuteScriptBehavior
Hosted->>Serializer: LoadModule(script.osc)
Serializer->>Disk: read MessagePack bytes
Serializer-->>Hosted: return IExecutableModule
Hosted->>Hosted: CreateProcess(host, module)
Hosted-->>User: start process / run script
end
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
- Check MessagePack key ordering and compatibility in
PrecompiledRuntimeModule. - Verify
ModuleSerializerfile I/O error handling and binary integrity. - Review
BuildPrecompiledBehaviorcompilation path and exception reporting. - Ensure
ExecuteScriptBehaviorextension check is case-insensitive and both branches release resources consistently. - Confirm
CreateProcess(IHostApplication, IExecutableModule)mirrors initialization without unintended side effects.
Poem
🐰
I nibbled bytes and packed them neat,
A .osc carrot—oh what a treat!
Save, then load, no parsing fuss,
Hop to run — swift code for us.
A tiny rabbit claps, "Build — let's trust!"
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly describes the main change: adding capability for pre-compiling scripts to accelerate startup, which aligns with the implementation of new build behavior, module serialization, and precompiled script execution features. |
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
Сделай, пожалуйста, статус черновика в пулреквесте, чтобы было понятно, когда wip закончился
Сделай, пожалуйста, статус черновика в пулреквесте, чтобы было понятно, когда wip закончился
@EvilBeaver Пересоздать его как draft? Или в текущем что-то проставить можно? А, все, нашел