capstone-rust / capstone-rs

high-level Capstone system bindings for Rust
213 stars 75 forks source link

Some performance changes #126

Closed clubby789 closed 2 years ago

clubby789 commented 2 years ago

This PR mostly just inlines property accesses, which gave performance improvements of up to 4-6x in my own project.

I also switched to using from_utf8_unchecked as the function requires valid UTF8 to be passed anyway. This gave some small performance improvements.

clubby789 commented 2 years ago

The API specifies that No checks are made for: valid UTF-8, so I'm removng a test that did pass invalid UTF8.

codecov[bot] commented 2 years ago

Codecov Report

Merging #126 (2e6e89b) into master (01a966d) will increase coverage by 0.01%. The diff coverage is 93.33%.

@@            Coverage Diff             @@
##           master     #126      +/-   ##
==========================================
+ Coverage   94.59%   94.60%   +0.01%     
==========================================
  Files          22       22              
  Lines        2666     2690      +24     
  Branches     2627     2651      +24     
==========================================
+ Hits         2522     2545      +23     
- Misses        144      145       +1     
Impacted Files Coverage Δ
capstone-rs/src/arch/evm.rs 92.30% <0.00%> (ø)
capstone-rs/src/error.rs 59.52% <ø> (ø)
capstone-rs/src/instruction.rs 93.91% <95.00%> (+0.09%) :arrow_up:
capstone-rs/src/ffi.rs 100.00% <100.00%> (ø)
capstone-rs/src/test.rs 97.61% <100.00%> (+0.01%) :arrow_up:
capstone-rs/examples/demo.rs 92.30% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0202ebb...2e6e89b. Read the comment docs.

tmfink commented 2 years ago

Great work on the change! Looks like we got about 2% improvement on our existing benchmarks (although we should add more benchmarks).

$ cargo bench --bench my_benchmark
disasm_x86              time:   [7.5322 ms 7.5525 ms 7.5865 ms]                       
                        change: [-2.4643% -2.1081% -1.5816%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) high mild
  1 (1.00%) high severe

disasm_x86_detail       time:   [21.147 ms 21.200 ms 21.265 ms]                              
                        change: [-2.3077% -1.9077% -1.5143%] (p = 0.00 < 0.05)
                        Performance has improved.