perf(array): add dense array fast-path for Array.prototype.unshift - #5329
perf(array): add dense array fast-path for Array.prototype.unshift#5329Exar04 wants to merge 1 commit into
Conversation
Signed-off-by: Exar04 <yashdhadwe@gmail.com>
c217680 to
a4a2a88
Compare
| let props = &mut o_borrow.properties_mut().indexed_properties; | ||
|
|
||
| let fast_path = match props { | ||
| IndexedProperties::DenseI32(dense) if dense.len() as u64 == len => { |
There was a problem hiding this comment.
Here we are iterating over values that will be added to array and converting it to type i32.
But what if we encounter string or f64? according to blog shared in issue, the type of array should get converted to lower type i.e DenseI32 -> DenseF64.
But we aren't doing that here (even before I added this code), is it getting handled somewhere else?
also if I am right about above, instead of getting out of match when encountering f64 instead of i32 it would be more performant to try again match.
something like this ->
fn main() {
let mut b = 1;
let a = loop {
match b {
1 => {
b = 2;
if b == 2{
continue
}
break "one"
},
2 => break "two",
_ => break "other",
}
};
println!("{}", a);
}but idk... its just a thought
| let new_len = len + arg_count; | ||
| Self::set_length(&o, new_len, context)?; | ||
| return Ok(new_len.into()); |
There was a problem hiding this comment.
I would put these three lines on each fast path instead. Even though it is a bit verbose, it doesn't require having complex branches, it's just a "if dense and all types match, push to array, adjust the length and return"
ref: #3407