summaryrefslogtreecommitdiff
path: root/array.c
Commit message (Collapse)AuthorAgeFilesLines
* Don't allow re-embedding frozen arraysPeter Zhu2022-12-231-2/+9
| | | | | | | | 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.
* Fix typo in array.cPeter Zhu2022-12-221-1/+1
| | | | We should be using the size of RArray and not RString for arrays.
* [DOC] Correct Array#compact! descriptionJonathan Lim2022-12-111-1/+1
|
* Introduce BOP_CMP for optimized comparisonDaniel Colson2022-12-061-14/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Fix typos (#6775)Yudai Takada2022-11-201-1/+1
| | | | | | | | | | | * s/Innteger/Integer/ * s/diretory/directory/ * s/Bufer/Buffer/ * s/defalt/default/ * s/covearge/coverage/
* Using UNDEF_P macroS-H-GAMELINKS2022-11-161-9/+9
|
* Set array capacity/shared immediately after allocPeter Zhu2022-11-141-5/+5
| | | | | | | 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.
* Use `roomof` macro for rounding up divisionsNobuyoshi Nakada2022-10-141-1/+1
|
* Add Data class implementation: Simple immutable value objectVictor Shepelev2022-09-301-1/+1
|
* [Bug #19029] Don't start GC during compactionMatt Valentine-House2022-09-291-5/+9
| | | | | | | | | | | | | | 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 (#5739)Jeremy Evans2022-08-111-1/+4
| | | | | | | | | | | | | | | | | | | | | | * 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>
* Make array slices views rather than copiesPeter Zhu2022-07-281-10/+29
| | | | | | 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.
* Use rb_ary_hidden_new for rb_ary_hidden_new_fillPeter Zhu2022-07-261-2/+1
|
* Rename rb_ary_tmp_new to rb_ary_hidden_newPeter Zhu2022-07-261-6/+4
| | | | | | 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.
* Remove ary_discardPeter Zhu2022-07-261-10/+1
| | | | | | 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.
* Remove reference counting for all frozen arraysPeter Zhu2022-07-221-28/+17
| | | | | | | | | | | 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.
* Remove unused variable in array.cPeter Zhu2022-07-211-1/+0
| | | | | array.c:460:14: warning: unused variable 'len' [-Wunused-variable] long len = ARY_HEAP_LEN(ary);
* Remove check for shared root arraysPeter Zhu2022-07-211-4/+2
| | | | | | All shared root arrays should not be on the transient heap. ary_make_shared evacuates arrays from the transient heap when creating shared roots.
* Expand tabs [ci skip]Takashi Kokubun2022-07-211-938/+938
| | | | [Misc #18891]
* Add comment in array.c about flagsPeter Zhu2022-07-211-0/+31
|
* Add RARRAY_SHARED_FLAGPeter Zhu2022-07-211-3/+3
|
* Refactor macros of array.cPeter Zhu2022-07-211-35/+7
| | | | | Move some macros in array.c to internal/array.h so that other files can also access these macros.
* Add RARRAY_LITERAL_FLAG for array literalsPeter Zhu2022-07-201-12/+34
| | | | | | | | | | | | | 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>
* Remove unused variable in array.cPeter Zhu2022-07-181-12/+11
| | | | vshared is no longer used.
* [Feature #18901] Support size pool movement for ArraysMatt Valentine-House2022-07-121-1/+41
| | | | | | | | | | | | | 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
* Add missing write barriers to Array#replaceAlan Wu2022-04-281-2/+4
| | | | | | | Previously it made object references without using write barriers, creating GC inconsistencies. See: http://ci.rvm.jp/results/trunk-gc-asserts@phosphorus-docker/3925529
* Correct whitespace in array.c (#5791)Burdette Lamar2022-04-111-10/+370
|
* [DOC] Enhanced RDoc for Array intro (#5781)Burdette Lamar2022-04-101-44/+90
| | | This covers the first few sections of the class doc for Array.
* [DOC] Use simple references to operator methodsNobuyoshi Nakada2022-03-261-5/+5
| | | | | | | 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.
* Fix formatting errors in What's Here for Array, Hash, ENV (#5718)Burdette Lamar2022-03-251-4/+4
|
* [DOC] Repair format and links in What's Here sections (#5711)Burdette Lamar2022-03-251-124/+126
| | | | | * Repair format and links in What's Here for Comparable and Array * Repair format for What's Here in enum.c
* [Feature #18634] Implement Arrays on Variable Width AllocationPeter Zhu2022-03-221-36/+155
| | | | | | 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.
* Assume that refcnt of shared root is non-negativePeter Zhu2022-03-141-7/+5
| | | | The refcnt of a shared root array should always be non-negative.
* Assume that shared_root exists in rb_ary_decrement_sharePeter Zhu2022-03-141-5/+3
| | | | | All callers of rb_ary_decrement_share guarantee that shared_root is not 0.
* Fix crash on GC stress and RGENGC_CHECK_MODE=2Peter Zhu2022-03-121-3/+6
| | | | | | 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.
* Add rb_ary_resetPeter Zhu2022-03-111-14/+9
| | | | rb_ary_reset will free heap allocated arrays and unshare shared arrays.
* Refactor duplicate code in rb_array_replacePeter Zhu2022-03-111-12/+7
| | | | | In both cases in the if statement, we free heap allocated arrays and unshare shared arrays.
* Use rb_ary_unshare for shared array in rb_ary_replacePeter Zhu2022-03-071-7/+1
| | | | | rb_ary_unshare will perform FL_UNSET_SHARED and rb_ary_decrement_share.
* Doc: fix documentation typo for Array#minRogerio Bordignon2022-03-031-1/+1
|
* [DOC] Fix documentation for Array#deleteVivek Bharath Akupatni2022-03-011-1/+1
| | | Never returns self.
* Use rb_ary_behead for rb_ary_shiftPeter Zhu2022-02-231-55/+28
| | | | | rb_ary_shift is just a special case of rb_ary_behead where we behead only 1 element.
* Use RARRAY_SHARED_ROOT_FLAG for checking re-enterPeter Zhu2022-02-141-3/+3
| | | | | 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.
* [DOC] Simplify operator method referencesNobuyoshi Nakada2022-02-121-8/+9
|
* [DOC] Adjustments to links in array.c (#5532)Burdette Lamar2022-02-081-13/+14
| | | Mostly suppressing links to itself.
* [DOC] Fix broken links to literals.rdocNobuyoshi Nakada2022-02-081-1/+1
|
* [DOC] Simplify links to global methodsNobuyoshi Nakada2022-02-081-1/+1
|
* [DOC] Use RDoc link style for links in the same class/modulePeter Zhu2022-02-071-10/+10
| | | | | | | | | | I used this regex: (?<=\[)#(?:class|module)-([A-Za-z]+)-label-([A-Za-z0-9\-\+]+) And performed a global find & replace for this: rdoc-ref:$1@$2
* [DOC] Use RDoc link style for links to other classes/modulesPeter Zhu2022-02-071-2/+2
| | | | | | | | | | I used this regex: ([A-Za-z]+)\.html#(?:class|module)-[A-Za-z]+-label-([A-Za-z0-9\-\+]+) And performed a global find & replace for this: rdoc-ref:$1@$2
* Adding links to literals and Kernel (#5192)Burdette Lamar2021-12-031-3/+10
| | | | * Adding links to literals and Kernel
* Use `Primitive.mandatory_only?` for `Array#sample`Koichi Sasada2021-11-151-1/+7
|