Граф коммитов

1141 Коммитов

Автор SHA1 Сообщение Дата
BurdetteLamar 53e3795379 [DOC] Tweaks to Array#bsearch_index 2024-08-21 12:07:28 -04:00
BurdetteLamar 65b3bcede3 [DOC] Tweaks for Array#collect 2024-08-21 11:59:20 -04:00
BurdetteLamar ee6c7ab0cf [DOC] Tweaks for Array#clear 2024-08-21 11:56:35 -04:00
BurdetteLamar 124f1754df [DOC] Tweaks for Array#bsearch 2024-08-21 11:42:20 -04:00
Burdette Lamar 77ac853c15
[DOC] Tweaks to Array#assoc (#11384) 2024-08-16 16:11:55 -04:00
BurdetteLamar 33bffde923 [DOC] Tweaks for Array#at 2024-08-15 12:52:09 -04:00
BurdetteLamar d2361ba156 [DOC] Tweaks for Array#push 2024-08-15 12:49:46 -04:00
BurdetteLamar edda29a117 [DOC] Fix Related for Array#all? 2024-08-15 12:48:27 -04:00
BurdetteLamar 1f994683b6 [DOC] Tweaks for Array#any? 2024-08-15 12:46:18 -04:00
Burdette Lamar 85f99b3828
[DOC] Tweaks to Array#all? (#11365) 2024-08-14 13:47:28 -04:00
Jean Boussier 6ee9a08d32 rb_setup_fake_ary: use precomputed flags
Setting up the fake array is a bit more expensive than would be
expected because `rb_ary_freeze` does a lot of checks and lookup
a shape transition.

If we assume fake arrays will always be frozen, we can precompute
the flags state and just assign it.
2024-08-10 10:09:14 +02:00
Burdette Lamar ec5436bc3a
[DOC] Tweaks for Array#[]= (#11329) 2024-08-08 16:09:32 -04:00
BurdetteLamar b9a9564c1f [DOC] Tweaks for Array#[] 2024-08-08 16:08:15 -04:00
BurdetteLamar d657205c58 [DOC] Tweaks for Array#[] 2024-08-08 16:08:15 -04:00
BurdetteLamar 6fee51069c [DOC] Tweaks for Array#== 2024-08-08 16:05:42 -04:00
Burdette Lamar 3719b3d74d
[DOC] Tweaks to Array#- (#11303) 2024-08-07 15:59:57 -04:00
Burdette Lamar 2a31410ebe
[DOC] Tweaks to Array#+ (#11302) 2024-08-07 15:59:01 -04:00
BurdetteLamar fa3d9fdaed [DOC] Tweaks to Array#<=> 2024-08-06 15:51:31 -04:00
BurdetteLamar 3471437630 [DOC] Tweaks for Array#<< 2024-08-06 15:45:45 -04:00
BurdetteLamar a793b5376c [DOC] Tweaks to Array#* 2024-08-06 15:38:29 -04:00
BurdetteLamar 66181fdda5 [DOC] Tweak to Array#& 2024-08-06 15:37:51 -04:00
BurdetteLamar 8aeca5ce40 Tweaks to Array::try_convert 2024-08-06 15:37:23 -04:00
BurdetteLamar be959c040e [DOC] Tweak for Array::[] 2024-08-06 14:39:16 -04:00
Jeremy Evans cc81437260 Rewrite Array.new documentation
Use plain paragraphs instead of a nested unordered list.

Remove some examples, including examples that produce warnings in
verbose mode or raise exceptions.

Explicitly document the common pitfall of using an expression as a
default value instead of using a block.
2024-07-31 13:04:42 -07:00
Burdette Lamar d2b8fd0f37
[DOC] Tweaks to Array.try_convert (#11260) 2024-07-30 16:31:33 -04:00
Burdette Lamar 91bb6afa75
[DOC] Tweaks for Array.new (#11259) 2024-07-30 10:09:06 -04:00
BurdetteLamar b44a154959 [DOC] Tweaks for Array#& 2024-07-30 10:06:41 -04:00
Aaron Patterson 2c1655314a Revert moving things to Ruby
This is slowing down benchmarks on x86, so lets revert it for now.
2024-07-29 14:18:11 -07:00
Burdette Lamar 477f672592
[DOC] rb_ary_s_create (#11256) 2024-07-29 09:11:35 -04:00
eileencodes 6f6aff56b1 Don't shrink array in `ary_make_shared`
This change adds back the assertions removed in #11092 and removes the
call to `ary_shrink_capa` from `ary_make_shared` when the array is
frozen.
2024-07-09 10:22:29 -07:00
Aaron Patterson b974c84606 Move Array#map to Ruby
Improves activerecord by about 1% on the interpreter:

```
before: ruby 3.4.0dev (2024-07-03T18:40:10Z master f88841b8f3) [arm64-darwin23]
after: ruby 3.4.0dev (2024-07-03T18:41:14Z ruby-map 6c0df4eb32) [arm64-darwin23]

------------  -----------  ----------  ----------  ----------  -------------  ------------
bench         before (ms)  stddev (%)  after (ms)  stddev (%)  after 1st itr  before/after
activerecord  235.2        0.8         233.6       0.7         1.01           1.01
------------  -----------  ----------  ----------  ----------  -------------  ------------
Legend:
- after 1st itr: ratio of before/after time for the first benchmarking iteration.
- before/after: ratio of before/after time. Higher is better for after. Above 1 represents a speedup.
```

Improves YJIT by about 4%:

```
before: ruby 3.4.0dev (2024-07-03T18:40:10Z master f88841b8f3) +YJIT [arm64-darwin23]
after: ruby 3.4.0dev (2024-07-03T18:41:14Z ruby-map 6c0df4eb32) +YJIT [arm64-darwin23]

------------  -----------  ----------  ----------  ----------  -------------  ------------
bench         before (ms)  stddev (%)  after (ms)  stddev (%)  after 1st itr  before/after
activerecord  142.1        1.2         137.0       0.6         1.00           1.04
------------  -----------  ----------  ----------  ----------  -------------  ------------
Legend:
- after 1st itr: ratio of before/after time for the first benchmarking iteration.
- before/after: ratio of before/after time. Higher is better for after. Above 1 represents a speedup.
```
2024-07-03 12:32:53 -07:00
Aaron Patterson 4c9134d2b2 Move Array#select to Ruby
This speeds up the mail benchmark by about 7% on the interpreter:

```
before: ruby 3.4.0dev (2024-07-03T17:01:41Z master f4b313f733) [arm64-darwin23]
after: ruby 3.4.0dev (2024-07-03T17:45:50Z ruby-select de282cacd5) [arm64-darwin23]

-----  -----------  ----------  ----------  ----------  -------------  ------------
bench  before (ms)  stddev (%)  after (ms)  stddev (%)  after 1st itr  before/after
mail   72.9         0.8         68.2        1.0         1.02           1.07
-----  -----------  ----------  ----------  ----------  -------------  ------------
Legend:
- after 1st itr: ratio of before/after time for the first benchmarking iteration.
- before/after: ratio of before/after time. Higher is better for after. Above 1 represents a speedup.
```

YJIT is about 13% faster:

```
before: ruby 3.4.0dev (2024-07-03T17:01:41Z master f4b313f733) +YJIT [arm64-darwin23]
after: ruby 3.4.0dev (2024-07-03T17:45:50Z ruby-select de282cacd5) +YJIT [arm64-darwin23]

-----  -----------  ----------  ----------  ----------  -------------  ------------
bench  before (ms)  stddev (%)  after (ms)  stddev (%)  after 1st itr  before/after
mail   51.0         0.8         45.2        0.6         1.00           1.13
-----  -----------  ----------  ----------  ----------  -------------  ------------
Legend:
- after 1st itr: ratio of before/after time for the first benchmarking iteration.
- before/after: ratio of before/after time. Higher is better for after. Above 1 represents a speedup.
```
2024-07-03 11:32:40 -07:00
Jean Boussier 786cf9db48 array.c: Remove outdated assertions
Following [Feature #20589] it can happen that we change the
capacity of a frozen array, so these assertions no longer make
sense.

Normally we don't hit them because `Array#freeze` shrinks the
array, but if somehow the Array was frozen using `Object#freeze`
then we may shrink it after it was frozen.
2024-07-03 17:16:17 +02:00
eileencodes d25b74b32c Resize arrays in `rb_ary_freeze` and use it for freezing arrays
While working on a separate issue we found that in some cases
`ary_heap_realloc` was being called on frozen arrays. To fix this, this
change does the following:

1) Updates `rb_ary_freeze` to assert the type is an array, return if
already frozen, and shrink the capacity if it is not embedded, shared
or a shared root.
2) Replaces `rb_obj_freeze` with `rb_ary_freeze` when the object is
always an array.
3) In `ary_heap_realloc`, ensure the new capa is set with
`ARY_SET_CAPA`. Previously the change in capa was not set.
4) Adds an assertion to `ary_heap_realloc` that the array is not frozen.

Some of this work was originally done in
https://github.com/ruby/ruby/pull/2640, referencing this issue
https://bugs.ruby-lang.org/issues/16291. There didn't appear to be any
objections to this PR, it appears to have simply lost traction.

The original PR made changes to arrays and strings at the same time,
this PR only does arrays. Also it was old enough that rather than revive
that branch I've made a new one. I added Lourens as co-author in addtion
to Aaron who helped me with this patch.

The original PR made this change for performance reasons, and while
that's still true for this PR, the goal of this PR is to avoid
calling `ary_heap_realloc` on frozen arrays. The capacity should be
shrunk _before_ the array is frozen, not after.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
Co-Authored-By: methodmissing <lourens@methodmissing.com>
2024-07-02 10:34:23 -07:00
Jean Boussier 7c12169230 Eliminate internal uses of `Data_Wrap_Struct`
Ref: https://github.com/ruby/ruby/pull/10872

These should be the last internal uses of the old `Data` API
inside Ruby itself. Some use remain in a couple default gems.
2024-06-02 13:59:11 +02:00
Nobuyoshi Nakada 49fcd33e13 Introduce a specialize instruction for Array#pack
Instructions for this code:

```ruby
  # frozen_string_literal: true

[a].pack("C")
```

Before this commit:

```
== disasm: #<ISeq:<main>@test.rb:1 (1,0)-(3,13)>
0000 putself                                                          (   3)[Li]
0001 opt_send_without_block                 <calldata!mid:a, argc:0, FCALL|VCALL|ARGS_SIMPLE>
0003 newarray                               1
0005 putobject                              "C"
0007 opt_send_without_block                 <calldata!mid:pack, argc:1, ARGS_SIMPLE>
0009 leave
```

After this commit:

```
== disasm: #<ISeq:<main>@test.rb:1 (1,0)-(3,13)>
0000 putself                                                          (   3)[Li]
0001 opt_send_without_block                 <calldata!mid:a, argc:0, FCALL|VCALL|ARGS_SIMPLE>
0003 putobject                              "C"
0005 opt_newarray_send                      2, :pack
0008 leave
```

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2024-05-23 12:11:50 -07:00
Matt Valentine-House c59abb9999 Rename ary_heap_alloc -> ary_heap_alloc_buffer
To differentiate it from ary_alloc_heap
2024-05-02 19:28:23 +01:00
Zack Deveau c479492a67 Resize ary when `Array#sort!` block modifies embedded ary
In cases where `rb_ary_sort_bang` is called with a block and
tmp is an embedded array, we need to account for the block
potentially impacting the capacity of ary.

ex:
```
var_0 = (1..70).to_a
var_0.sort! do |var_0_block_129, var_1_block_129|
  var_0.pop
  var_1_block_129 <=> var_0_block_129
end.shift(3)
```

The above example can put the array into a corrupted state
resulting in a heap buffer overflow and possible segfault:
```
ERROR: AddressSanitizer: heap-buffer-overflow on address [...]
WRITE of size 560 at 0x60b0000034f0 thread T0 [...]
```

This commit adds a conditional to determine when the capacity
of ary has been modified by the provided block. If this is
the case, ensure that the capacity of ary is adjusted to
handle at minimum the len of tmp.
2024-04-14 08:41:47 +09:00
KJ Tsanaktsidis 9d0a5148ae Add missing RB_GC_GUARDs related to DATA_PTR
I discovered the problem in `compile.c` from a failing
TestIseqLoad#test_stressful_roundtrip test with ASAN enabled. The other
two changes in array.c and string.c I found by auditing similar usages
of DATA_PTR in the codebase.

[Bug #20402]
2024-03-31 20:33:38 +11:00
Burdette Lamar 76f9cfd0b9
[DOC] Array doc (#10199) 2024-03-13 14:50:18 -04:00
BurdetteLamar cc757f4a61 Add 'In brief' for Array#[] 2024-03-06 16:42:29 -05:00
Peter Zhu df5b8ea4db Remove unneeded RUBY_FUNC_EXPORTED 2024-02-23 10:24:21 -05:00
Burdette Lamar 65f5435540
[DOC] Doc compliance (#9955) 2024-02-14 10:47:42 -05:00
BurdetteLamar f41d8f38b4 Comply with doc guide 2024-02-12 16:52:14 -05:00
Peter Zhu 1228751af6 Replace assert with RUBY_ASSERT in array.c
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
2024-02-12 15:07:47 -05:00
Takashi Kokubun c84237f953
Rewrite Array#each in Ruby using Primitive (#9533) 2024-01-23 20:09:57 +00:00
Edwing123 a660e1de18
[DOC] correct doc comment for rb_ary_aset
Signed-off-by: Edwin Garcia <egarciavalle2014@gmail.com>
2024-01-18 06:56:42 +00:00
Akshay Birajdar c06745fec9 [DOC] Enhance documentation for `Array#zip` 2024-01-09 14:13:20 -05:00
Peter Zhu 26172c9701 [DOC] Add parentheses to Array#eql?
Makes the call-seq and code more consistent in format.
2023-12-27 11:11:42 -05:00
Peter Zhu ca886cd253 [DOC] Link to Array#eql? from Array#hash 2023-12-25 13:56:15 -05:00