Skip to content

Remove the serialization size bottleneck#25

Draft
FTRobbin wants to merge 25 commits intomainfrom
haobin-mining
Draft

Remove the serialization size bottleneck#25
FTRobbin wants to merge 25 commits intomainfrom
haobin-mining

Conversation

@FTRobbin
Copy link
Copy Markdown
Collaborator

@FTRobbin FTRobbin commented Mar 3, 2026

  • Replace serde_json with serde/flexbuffers.
  • Implement a debug feature that prints the size of serialized egraphs.

Output example:

cargo run --bin poach tests/taylor51.egg tempo/ size-report
egglog::EGraph : 4.97GB
. rulesets : 4.06GB (81.82%)
. functions : 0.44GB (8.95%)
. backend : 13.59MB (0.27%)
. type_info : 0.24MB (0.00%)
. overall_run_report : 148.99KB (0.00%)
. proof_state : 78B (0.00%)
. schedulers : 27B (0.00%)
. commands : 7B (0.00%)
. command_macros : 7B (0.00%)
. pushed_egraph : 3B (0.00%)
[1/1] taylor51 : SUCCESS
0 failures out of 1 files

*Numbers were off by a bit from the Mar 2nd meeting version because I eyeballed the size from the number in bytes for the meeting and used base 1000 instead of 1024.

  • Investigate the problem in rulesets.

The problem is in span. The egglog frontend uses spans throughout its ASTs for debugging.

pub enum Span {
    Panic,
    Egglog(Arc<EgglogSpan>),
    Rust(Arc<RustSpan>),
}

...

pub struct EgglogSpan {
    pub file: Arc<SrcFile>,
    pub i: usize,
    pub j: usize,
}

However, the default implementation generated by #[derive(serde::Serialize)] performs a deep copy for Arc<SrcFile>, which means every node in the AST would carry a copy of the whole input egglog program, causing a significant blowup that scales quadratically with the input file size (# AST nodes * filesize).

  • Remove the span serialization bottleneck.

I implemented a quick hack that serializes span into unit. For the example tested above, we now have a 300x overall reduction and a 1600x reduction for rulesets and functions:

&egglog::EGraph : 17.12MB
  backend : 13.56MB (79.24%)
  rulesets : 2.53MB (14.80%)
  functions : 0.72MB (4.25%)
  type_info : 0.24MB (1.42%)
  overall_run_report : 148.99KB (0.85%)
  proof_state : 78B (0.00%)
  schedulers : 27B (0.00%)
  pushed_egraph : 3B (0.00%)
[1/1] taylor51 : SUCCESS
0 failures out of 1 files
  • Add experiments previously blocked by the serialization size.

Run extract runmode on easteregg, herbie-hamming, herbie-math-rewrite, herbie-math-taylor benchmarks.

Fixed minor bugs.

  • Update nightly frontend to present the new data

Added radio buttons to pick a benchmark.

Added a new chart to show the speedup of using Poach vs. Vanilla.

Added a checkbox for including deserialization time in Poach time.

  • Get a nightly run. Link

  • List what research questions to ask and how to look at the data.

  • Add file size statistics to the nightly report. (Link in the #poach channel)

  • Is the serialization size linear to the egraph size? - Yes (~500bytes per tuple)

  • Is the serialization/deserialization time linear to the serialization size? - Yes

  • Clean up hacks.

  • Get another nightly run. Link Results reproduced.

  • Investigate if egglog's hashcon works as I thought it does

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant