| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
| |
[Bug #19530]
If the initial value isn't one of the special cased types, we directly
jump to the slow path.
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
For example:
```ruby
def my_func(x, y, *rest)
p [x, y, rest]
end
my_func(1, 2, 3, *[4, 5])
```
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Sharing an array will cause it to be WB unprotected due to the use
of `RARRAY_PTR`. We don't need to WB unprotect the array because we're
not writing to the buffer of the array.
The following script demonstrates this issue:
```
ary = [1] * 1000
shared = ary[10..20]
puts ObjectSpace.dump(ary)
```
|
|
|
|
|
|
| |
Freeing the memory of a Hash should be done by the garbage collector
and not by array functions. This could potentially leak memory if
ary_recycle_hash was not implemented properly.
|
|
|
|
| |
We don't need ARY_SET_SHARED since we already have rb_ary_set_shared.
|
|
|
|
|
|
|
|
| |
Frozen arrays should not move from heap allocated to embedded because
frozen arrays could be shared roots for other (shared) arrays. If the
frozen array moves from heap allocated to embedded it would cause issues
since the shared array would no longer know where to set the pointer
in the shared root.
|
|
|
|
| |
We should be using the size of RArray and not RString for arrays.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Prior to this commit the `OPTIMIZED_CMP` macro relied on a method lookup
to determine whether `<=>` was overridden. The result of the lookup was
cached, but only for the duration of the specific method that
initialized the cmp_opt_data cache structure.
With this method lookup, `[x,y].max` is slower than doing `x > y ?
x : y` even though there's an optimized instruction for "new array max".
(John noticed somebody a proposed micro-optimization based on this fact
in https://github.com/mastodon/mastodon/pull/19903.)
```rb
a, b = 1, 2
Benchmark.ips do |bm|
bm.report('conditional') { a > b ? a : b }
bm.report('method') { [a, b].max }
bm.compare!
end
```
Before:
```
Comparison:
conditional: 22603733.2 i/s
method: 19820412.7 i/s - 1.14x (± 0.00) slower
```
This commit replaces the method lookup with a new CMP basic op, which
gives the examples above equivalent performance.
After:
```
Comparison:
method: 24022466.5 i/s
conditional: 23851094.2 i/s - same-ish: difference falls within
error
```
Relevant benchmarks show an improvement to Array#max and Array#min when
not using the optimized newarray_max instruction as well. They are
noticeably faster for small arrays with the relevant types, and the same
or maybe a touch faster on larger arrays.
```
$ make benchmark COMPARE_RUBY=<master@5958c305> ITEM=array_min
$ make benchmark COMPARE_RUBY=<master@5958c305> ITEM=array_max
```
The benchmarks added in this commit also look generally improved.
Co-authored-by: John Hawthorn <jhawthorn@github.com>
|
|
|
|
|
|
|
|
|
|
|
| |
* s/Innteger/Integer/
* s/diretory/directory/
* s/Bufer/Buffer/
* s/defalt/default/
* s/covearge/coverage/
|
| |
|
|
|
|
|
|
|
| |
If auto-compaction is enabled, then we have to set the capacity/shared
immediately after allocating a heap array. If compaction runs before
capacity/shared is set then it could cause the array to be re-embedded,
which can cause crashes.
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
RARRAY_PTR when called with a transient array detransients the array
before returning its pointer which allocates in the heap.
Because RARRAY_PTR was being used during compaction (when re-embedding
arrays that have moved between size pools) this introduces the
possibility that we can hit a malloc threshold, triggering GC, while in
the middle of compaction.
We should avoid this by using safer functions to get hold of the
pointer. Since we know that the array is not embedded here, we can use
ARY_HEAP_PTR and ARY_EMBED_PTR directly
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* Fix Array#[] with ArithmeticSequence with negative steps
Previously, Array#[] when called with an ArithmeticSequence
with a negative step did not handle all cases correctly,
especially cases involving infinite ranges, inverted ranges,
and/or exclusive ends.
Fixes [Bug #18247]
* Add Array#slice tests for ArithmeticSequence with negative step to test_array
Add tests of rb_arithmetic_sequence_beg_len_step C-API function.
* Fix ext/-test-/arith_seq/beg_len_step/depend
* Rename local variables
* Fix a variable name
Co-authored-by: Kenta Murata <3959+mrkn@users.noreply.github.com>
|
|
|
|
|
|
| |
Before this commit, if the slice fits in VWA, it would make a copy
rather than a view. This is slower as it requires a memcpy of the
contents.
|
| |
|
|
|
|
|
|
| |
rb_ary_tmp_new suggests that the array is temporary in some way, but
that's not true, it just creates an array that's hidden and not on the
transient heap. This commit renames it to rb_ary_hidden_new.
|
|
|
|
|
|
| |
ary_discard should not be used as it should be handled by the GC. The
only user of ary_discard is rb_ary_product, which doesn't neeed to use
ary_discard.
|
|
|
|
|
|
|
|
|
|
|
| |
The RARRAY_LITERAL_FLAG was added in commit
5871ecf956711fcacad7c03f2aef95115ed25bc4 to improve CoW performance for
array literals by not keeping track of reference counts.
This commit reverts that commit and has an alternate implementation that
is more generic for all frozen arrays. Since frozen arrays cannot be
modified, we don't need to set the RARRAY_SHARED_ROOT_FLAG and we don't
need to do reference counting.
|
|
|
|
|
| |
array.c:460:14: warning: unused variable 'len' [-Wunused-variable]
long len = ARY_HEAP_LEN(ary);
|
|
|
|
|
|
| |
All shared root arrays should not be on the transient heap.
ary_make_shared evacuates arrays from the transient heap when creating
shared roots.
|
|
|
|
| |
[Misc #18891]
|
| |
|
| |
|
|
|
|
|
| |
Move some macros in array.c to internal/array.h so that other files
can also access these macros.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Array created as literals during iseq compilation don't need a
reference count since they can never be modified. The previous
implementation would mutate the hidden array's reference count,
causing copy-on-write invalidation.
This commit adds a RARRAY_LITERAL_FLAG for arrays created through
rb_ary_literal_new. Arrays created with this flag do not have reference
count stored and just assume they have infinite number of references.
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
|
|
|
|
| |
vshared is no longer used.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit enables Arrays to move between size pools during compaction.
This can occur if the array is mutated such that it would fit in a
different size pool when embedded.
The move is carried out in two stages:
1. The RVALUE is moved to a destination heap during object movement
phase of compaction
2. The array data is re-embedded and the original buffer free'd if
required. This happens during the update references step
|
|
|
|
|
|
|
| |
Previously it made object references without using write barriers,
creating GC inconsistencies.
See: http://ci.rvm.jp/results/trunk-gc-asserts@phosphorus-docker/3925529
|
| |
|
|
|
| |
This covers the first few sections of the class doc for Array.
|
|
|
|
|
|
|
| |
Method references is not only able to be marked up as code, also
reflects `--show-hash` option.
The bug that prevented the old rdoc from correctly parsing these
methods was fixed last month.
|
| |
|
|
|
|
|
| |
* Repair format and links in What's Here for Comparable and Array
* Repair format for What's Here in enum.c
|
|
|
|
|
|
| |
This commit implements arrays on Variable Width Allocation. This allows
longer arrays to be embedded (i.e. contents directly follow the object
header) which improves performance through better cache locality.
|
|
|
|
| |
The refcnt of a shared root array should always be non-negative.
|
|
|
|
|
| |
All callers of rb_ary_decrement_share guarantee that
shared_root is not 0.
|
|
|
|
|
|
| |
rb_ary_reset could leave the array in a bad state since it frees memory
but does not unset any flags. This can cause a crash on GC stress. This
commit changes rb_ary_reset to set the array as an empty embedded array.
|
|
|
|
| |
rb_ary_reset will free heap allocated arrays and unshare shared arrays.
|
|
|
|
|
| |
In both cases in the if statement, we free heap allocated arrays and
unshare shared arrays.
|
|
|
|
|
| |
rb_ary_unshare will perform FL_UNSET_SHARED and
rb_ary_decrement_share.
|
| |
|
|
|
| |
Never returns self.
|
|
|
|
|
| |
rb_ary_shift is just a special case of rb_ary_behead where we behead
only 1 element.
|
|
|
|
|
| |
RARRAY_SHARED_ROOT_FLAG is defined as FL_USER5, but we should use
RARRAY_SHARED_ROOT_FLAG instead of depending on that they're equal.
|