Skip to content

Commit

Permalink
Stop using RArray::push in func call
Browse files Browse the repository at this point in the history
Instead, use a Vec to hold the Values, and convert that Vec into
a RArray for fewer calls into Ruby.

Baseline (main):
```
Call host func (4 args)
                        505.454k (± 1.1%) i/s -      2.530M in   5.006521s
Call host func (16 args)
                        413.965k (± 1.4%) i/s -      2.074M in   5.011759s
Call host func (64 args)
                        241.831k (± 0.8%) i/s -      1.220M in   5.044257s
Call host func (128 args)
                        124.092k (± 1.0%) i/s -    621.550k in   5.009287s
Call host func (256 args)
                         48.621k (± 1.9%) i/s -    245.100k in   5.042940s
```

This commit:
```
Call host func (4 args)
                        518.697k (± 0.9%) i/s -      2.634M in   5.079016s
Call host func (16 args)
                        443.826k (± 0.8%) i/s -      2.227M in   5.018984s
Call host func (64 args)
                        272.471k (± 0.9%) i/s -      1.388M in   5.094768s
Call host func (128 args)
                        142.090k (± 0.7%) i/s -    724.506k in   5.099148s
Call host func (256 args)
                         56.107k (± 1.1%) i/s -    281.200k in   5.012444s
```
  • Loading branch information
jbourassa committed Apr 22, 2023
1 parent ba87587 commit cb6125b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ext/src/ruby_api/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,12 @@ impl<'a> Func<'a> {
[] => Ok(().into_value()),
[result] => result.to_ruby_value(store),
_ => {
let array = RArray::with_capacity(results.len());
let mut ruby_values : Vec<Value> = Vec::with_capacity(results.len());
for result in results {
array.push(result.to_ruby_value(store)?)?;
// Q: can this trigger GC?
ruby_values.push(result.to_ruby_value(store)?);
}
Ok(array.as_value())
Ok(*RArray::from_slice(&ruby_values))
}
}
}
Expand Down

0 comments on commit cb6125b

Please sign in to comment.