Skip to content

Optimize the size of Instruction#2365

Merged
coolreader18 merged 10 commits into
masterfrom
coolreader18/optimize-bytecode-format
Dec 16, 2020
Merged

Optimize the size of Instruction#2365
coolreader18 merged 10 commits into
masterfrom
coolreader18/optimize-bytecode-format

Conversation

@coolreader18

@coolreader18 coolreader18 commented Dec 10, 2020

Copy link
Copy Markdown
Member

This reduces the size of the Instruction enum from 56 bytes to 16 bytes, which should help with memory usage as well as a (very) slight performance boost:

Benchmark #1: ./rustpython-norm benchmarks/pystone.py 50000
  Time (mean ± σ):      3.655 s ±  0.119 s    [User: 3.637 s, System: 0.007 s]
  Range (min … max):    3.522 s …  3.853 s    10 runs
 
Benchmark #2: ./rustpython-opt benchmarks/pystone.py 50000
  Time (mean ± σ):      3.624 s ±  0.074 s    [User: 3.601 s, System: 0.008 s]
  Range (min … max):    3.557 s …  3.783 s    10 runs
 
Summary
  './rustpython-opt benchmarks/pystone.py 50000' ran
    1.01 ± 0.04 times faster than './rustpython-norm benchmarks/pystone.py 50000'

The instructions I changed were either a) flattening an inner enum, like CallFunction { CallType } -> CallFunction{Positional,Keyword,Ex} b) not in many hot paths, like Import, or c) provided redundant information, like SetupLoop, whose start field always pointed to lasti+1

Edit: well, SetupLoop isn't actually like that, but there was a way around it

@coolreader18 coolreader18 force-pushed the coolreader18/optimize-bytecode-format branch from d1a5081 to b90bb34 Compare December 10, 2020 19:37
@coolreader18

Copy link
Copy Markdown
Member Author

Here's the benchmark for the lz4_flex change:

Benchmark #1: ./rustpython-norm -c ""
  Time (mean ± σ):      53.1 ms ±  13.2 ms    [User: 45.4 ms, System: 7.3 ms]
  Range (min … max):    36.3 ms …  77.2 ms    66 runs
 
Benchmark #2: ./rustpython-opt -c ""
  Time (mean ± σ):      15.2 ms ±   7.4 ms    [User: 11.0 ms, System: 4.2 ms]
  Range (min … max):     7.7 ms …  33.8 ms    206 runs
 
Summary
  './rustpython-opt -c ""' ran
    3.50 ± 1.92 times faster than './rustpython-norm -c ""'

@coolreader18 coolreader18 force-pushed the coolreader18/optimize-bytecode-format branch 2 times, most recently from 8bbe430 to 9b65cd3 Compare December 11, 2020 18:32
@coolreader18 coolreader18 force-pushed the coolreader18/optimize-bytecode-format branch from 9b65cd3 to 1be79c9 Compare December 14, 2020 21:56
Comment thread bytecode/src/bytecode.rs
pub fn from_bytes(data: &[u8]) -> Result<Self, Box<dyn std::error::Error>> {
let reader = lz_fear::framed::LZ4FrameReader::new(data)?;
Ok(bincode::deserialize_from(reader.into_read())?)
// TODO: PR to lz4_flex to make it not panic

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this solved comment?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not yet, I haven't made a PR

@coolreader18 coolreader18 merged commit 2d246f0 into master Dec 16, 2020
@youknowone youknowone deleted the coolreader18/optimize-bytecode-format branch December 16, 2020 15:02
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.

2 participants