113 lines
6.0 KiB
Markdown
113 lines
6.0 KiB
Markdown
---
|
|
id: DEC-0018
|
|
ticket: perf-vm-allocation-and-copy-pressure
|
|
title: Decision - [PERF] VM Allocation and Copy Pressure Baseline
|
|
status: in_progress
|
|
created: 2026-04-20
|
|
accepted: 2026-04-20
|
|
agenda: AGD-0013
|
|
plans: [PLN-0033, PLN-0034, PLN-0035]
|
|
tags: [perf, runtime, vm, memory, strings, allocation]
|
|
---
|
|
|
|
# Status
|
|
|
|
Accepted on 2026-04-20 and now in progress through linked implementation plans.
|
|
|
|
# Contexto
|
|
|
|
O core da VM ainda apresenta churn de alocacao e copia em caminhos relevantes, em especial:
|
|
|
|
- concatenacao de string em `ADD`;
|
|
- clone de valores em `GET_GLOBAL`;
|
|
- montagem de strings dinamicas em faults e logs.
|
|
|
|
O estado atual do runtime permite strings como parte legitima da linguagem, mas a representacao pratica ainda empurra payload caro para copias repetidas em alguns caminhos. A discussao da agenda fechou que o problema arquitetural nao e eliminar toda alocacao, e sim impedir recopia desnecessaria depois da primeira materializacao dos dados.
|
|
|
|
# Decisao
|
|
|
|
1. Strings SHALL remain part of the supported VM language surface.
|
|
2. The runtime MUST treat string payload as potentially expensive in the baseline performance model.
|
|
3. Hardcoded strings MAY pay one materialization cost during build/load into the constant pool, and runtime hot paths SHOULD preferentially reference that already-materialized representation.
|
|
4. Dynamically produced strings MAY pay an initial runtime materialization cost in dynamic storage, but the runtime MUST NOT introduce repeated implicit payload copies on hot paths unless the operation semantically requires a new string value.
|
|
5. `GET_GLOBAL` SHALL NOT gain new public semantics. Any reduction in copy pressure MUST come from internal representation, ownership strategy, or storage process, not from a guest-visible ABI change.
|
|
6. The baseline engineering target for the VM happy path SHALL be zero allocation on numeric and already-materialized hot paths.
|
|
7. That zero-allocation target SHALL remain an internal engineering objective and MUST NOT be published as a certification contract or guest-facing compatibility guarantee.
|
|
8. Fault and log paths MUST remain correct, deterministic, and readable, but they SHALL NOT drive the primary optimization strategy for the VM hot path.
|
|
|
|
# Rationale
|
|
|
|
Esta decisao fecha tres tensoes da agenda:
|
|
|
|
- preserva string como capacidade real da linguagem, sem prometer que string e "cheap" por definicao;
|
|
- evita reabrir a ABI publica apenas para aliviar pressao de copia em um ponto interno da VM;
|
|
- separa meta de engenharia de contrato normativo externo.
|
|
|
|
O custo inevitavel e a primeira materializacao:
|
|
|
|
- string hardcoded entra na constant pool em build/load;
|
|
- string dinamica nasce em runtime.
|
|
|
|
O custo evitavel e a recopia posterior do payload em caminhos quentes que ja deveriam operar sobre valor materializado, handle ou ownership mais barato.
|
|
|
|
Essa linha tambem mantem a arquitetura coerente com as specs atuais:
|
|
|
|
- valores triviais continuam baratos por copia;
|
|
- objetos com identidade e lifetime relevante continuam candidatos naturais a representacao por handle;
|
|
- tooling host-owned continua podendo observar heap e pressao de memoria sem que a VM precise transformar cada opcode em um ponto de instrumentacao intrusivo.
|
|
|
|
# Invariantes / Contrato
|
|
|
|
- The VM MUST preserve the public meaning of string values as guest-visible values.
|
|
- The VM MUST NOT change the public behavior of `GET_GLOBAL` as part of this decision.
|
|
- The runtime MUST distinguish first materialization from repeated implicit copy when evaluating optimization work.
|
|
- Constant-pool-backed strings SHOULD be treated as already materialized data for runtime access purposes.
|
|
- Runtime-created strings MAY allocate once at creation time.
|
|
- Hot-path operations over numeric values, handles, and already-materialized values SHOULD converge toward zero allocation.
|
|
- Any future move to heap-backed canonical strings, interning, copy-on-write, or similar global representation changes MUST be proposed in a separate decision if it changes operational constraints or implementation complexity materially.
|
|
- Fault generation and logs MAY allocate outside the happy path, provided they remain deterministic and do not leak into hot-loop design as a hidden steady-state cost.
|
|
|
|
# Impactos
|
|
|
|
- Spec
|
|
- No immediate guest-visible ABI change is required.
|
|
- Existing memory/value/debug specs remain directionally compatible.
|
|
- A follow-up plan may update wording in runtime specs to distinguish first materialization from repeated copy pressure more explicitly.
|
|
|
|
- Runtime
|
|
- Optimization work MUST target internal ownership and representation first.
|
|
- `GET_GLOBAL` copy pressure MUST be addressed without semantic drift.
|
|
- String-heavy `ADD` and similar paths become explicit hot-path optimization candidates.
|
|
|
|
- Host
|
|
- Certification and tooling remain host-owned.
|
|
- Allocation counters may exist as engineering telemetry, but they are not promoted to public certification criteria by this decision.
|
|
|
|
- Firmware / Tooling
|
|
- No cartridge author contract changes are introduced.
|
|
- Compiler/loader/tooling MAY continue to materialize hardcoded strings into constant-pool storage.
|
|
|
|
# Referencias
|
|
|
|
- `AGD-0013`
|
|
- `docs/specs/runtime/02a-vm-values-and-calling-convention.md`
|
|
- `docs/specs/runtime/03-memory-stack-heap-and-allocation.md`
|
|
- `docs/specs/runtime/10-debug-inspection-and-profiling.md`
|
|
- `crates/console/prometeu-vm/src/virtual_machine.rs`
|
|
- `crates/console/prometeu-system/src/virtual_machine_runtime/tick.rs`
|
|
|
|
# Propagacao Necessaria
|
|
|
|
- Create a plan that separates:
|
|
- hot-path ownership work in the VM core;
|
|
- telemetry/internal measurement work;
|
|
- any optional spec wording cleanup.
|
|
- Audit `GET_GLOBAL` and string-producing opcode paths under this contract.
|
|
- Define implementation evidence for "zero alloc on happy path" as internal profiling evidence rather than certification output.
|
|
- Do not reopen public ABI or language semantics during plan execution unless new evidence shows the current contract is insufficient.
|
|
|
|
# Revision Log
|
|
|
|
- 2026-04-20: Initial draft from AGD-0013.
|
|
- 2026-04-20: Accepted and linked to PLN-0033, PLN-0034, and PLN-0035.
|