Skip to content

Commit

Permalink
feat(air-parser)!: optimize Instruction type layout (#767)
Browse files Browse the repository at this point in the history
Instead of being boxed for each node, the `Instruction` type contains a boxed variable-size elements.  Thus `Instruction` is quite lean, and the allocator deals with variable-sized elements.

Total number of allocations is more or less same, but less space is wasted for unused memory: previously the Instruction's size was 112 bytes in WASM, now it is 16.

It reduces memory consumption on large AIR scripts (heap size decreased from 7.7MiB to 4.625MiB in parser-10000-100, and for the new parser-calls-10000-100 benchmark, it decreased from 5.115MiB to 4.375MiB).

This is a breaking change as the API changes (though the code that navigates the parsed tree generally should work as is).
  • Loading branch information
monoid authored Dec 12, 2023
1 parent f1b6c48 commit 1673cdf
Show file tree
Hide file tree
Showing 16 changed files with 1,471 additions and 1,367 deletions.
2 changes: 1 addition & 1 deletion air/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub mod parser {
pub use air_parser::ast::Instruction;

/// Parse an AIR script to AST.
pub fn parse(script: &str) -> Result<Box<Instruction<'_>>, String> {
pub fn parse(script: &str) -> Result<Instruction<'_>, String> {
air_parser::parse(script)
}
}
Expand Down
2 changes: 1 addition & 1 deletion air/src/preparation_step/preparation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub(crate) fn prepare<'i>(
run_parameters: RunParameters,
signature_store: SignatureStore,
) -> PreparationResult<PreparationDescriptor<'static, 'i>> {
let air: Instruction<'i> = *air_parser::parse(raw_air).map_err(PreparationError::AIRParseError)?;
let air: Instruction<'i> = air_parser::parse(raw_air).map_err(PreparationError::AIRParseError)?;

let prev_ingredients = ExecCtxIngredients {
last_call_request_id: prev_data.last_call_request_id,
Expand Down
Loading

0 comments on commit 1673cdf

Please sign in to comment.