-
Notifications
You must be signed in to change notification settings - Fork 5.5k
ZJIT: Add ArrayAsetFixnum instruction to hir #15747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
c3280a3 to
a7e915e
Compare
| self.assert_subtype(insn_id, index, types::Fixnum) | ||
| } | ||
| Insn::ArrayAsetFixnum { array, index, .. } => { | ||
| self.assert_subtype(insn_id, array, types::Array)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure we should optimize for subclasses here, since it seems we don’t for Hash. Maybe Array should follow the same rule? (ArrayArefFixnum currently allows the subclasses to be optimized though.)
| let index = fun.coerce_to(block, index, types::Fixnum, state); | ||
| let val = fun.coerce_to(block, val, types::BasicObject, state); | ||
|
|
||
| let _ = fun.push_insn(block, hir::Insn::ArrayAsetFixnum { array: recv, index, val, state }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although Max’s comment in the original issue suggested adding a length check here, I thought this might be sufficient since the called C function will handle it anyway.
That said, I’m not entirely confident, please let me know if I’m missing something.
Also, if we want to make this leaf/nogc, do we need additional guards for not frozen / not shared before treating it as leaf/nogc...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: Below is the breakdown of in-bounds vs. out-of-bounds for the inline Array#[]= path using several benchmarks. (related to Shopify#804 (comment))
Terms:
array_aset_fixnum_inline_count: Number of times we took the inline Array#[]= fast path with a Fixnum indexarray_aset_fixnum_inline_in_bounds_count: Among those inline calls, how many had an index within bounds (0 <= idx < len or -len <= idx < 0).array_aset_fixnum_inline_oob_count: Among those inline calls, how many had an out-of-bounds index.
Results:
- optcarrot
array_aset_fixnum_inline_count: 1,018,328
array_aset_fixnum_inline_in_bounds_count: 1,016,305
array_aset_fixnum_inline_oob_count: 2,023
- liquid-render
array_aset_fixnum_inline_count: 35
array_aset_fixnum_inline_in_bounds_count: 0
array_aset_fixnum_inline_oob_count: 35
- railsbench
array_aset_fixnum_inline_count: 131,681
array_aset_fixnum_inline_in_bounds_count: 131,681
array_aset_fixnum_inline_oob_count: 0
a7e915e to
5ef58f9
Compare
This comment has been minimized.
This comment has been minimized.
64f31f5 to
a7a557d
Compare
a7a557d to
19d5b63
Compare
Closes: Shopify#804
Benchmark
optcarrot
Average of last 10, non-warmup iters: 7019msAverage of last 10, non-warmup iters: 6931msbefore patch
after patch