summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
5 daysUse `set_table` to track const cachesJean Boussier
Now that we have a `set_table` implementation, we can use it to track const caches and save some memory. We could even save some more memory if `numtable` didn't store a copy of the `hash` and instead recomputed it every time, but this is a quick win. Notes: Merged: https://github.com/ruby/ruby/pull/13184
5 daysImplement Set as a core classJeremy Evans
Set has been an autoloaded standard library since Ruby 3.2. The standard library Set is less efficient than it could be, as it uses Hash for storage, which stores unnecessary values for each key. Implementation details: * Core Set uses a modified version of `st_table`, named `set_table`. than `s/st_/set_/`, the main difference is that the stored records do not have values, making them 1/3 smaller. `st_table_entry` stores `hash`, `key`, and `record` (value), while `set_table_entry` only stores `hash` and `key`. This results in large sets using ~33% less memory compared to stdlib Set. For small sets, core Set uses 12% more memory (160 byte object slot and 64 malloc bytes, while stdlib set uses 40 for Set and 160 for Hash). More memory is used because the set_table is embedded and 72 bytes in the object slot are currently wasted. Hopefully we can make this more efficient and have it stored in an 80 byte object slot in the future. * All methods are implemented as cfuncs, except the pretty_print methods, which were moved to `lib/pp.rb` (which is where the pretty_print methods for other core classes are defined). As is typical for core classes, internal calls call C functions and not Ruby methods. For example, to check if something is a Set, `rb_obj_is_kind_of` is used, instead of calling `is_a?(Set)` on the related object. * Almost all methods use the same algorithm that the pure-Ruby implementation used. The exception is when calling `Set#divide` with a block with 2-arity. The pure-Ruby method used tsort to implement this. I developed an algorithm that only allocates a single intermediate hash and does not need tsort. * The `flatten_merge` protected method is no longer necessary, so it is not implemented (it could be). * Similar to Hash/Array, subclasses of Set are no longer reflected in `inspect` output. * RDoc from stdlib Set was moved to core Set, with minor updates. This includes a comprehensive benchmark suite for all public Set methods. As you would expect, the native version is faster in the vast majority of cases, and multiple times faster in many cases. There are a few cases where it is significantly slower: * Set.new with no arguments (~1.6x) * Set#compare_by_identity for small sets (~1.3x) * Set#clone for small sets (~1.5x) * Set#dup for small sets (~1.7x) These are slower as Set does not currently use the AR table optimization that Hash does, so a new set_table is initialized for each call. I'm not sure it's worth the complexity to have an AR table-like optimization for small sets (for hashes it makes sense, as small hashes are used everywhere in Ruby). The rbs and repl_type_completor bundled gems will need updates to support core Set. The pull request marks them as allowed failures. This passes all set tests with no changes. The following specs needed modification: * Modifying frozen set error message (changed for the better) * `Set#divide` when passed a 2-arity block no longer yields the same object as both the first and second argument (this seems like an issue with the previous implementation). * Set-like objects that override `is_a?` such that `is_a?(Set)` return `true` are no longer treated as Set instances. * `Set.allocate.hash` is no longer the same as `nil.hash` * `Set#join` no longer calls `Set#to_a` (it calls the underlying C function). * `Set#flatten_merge` protected method is not implemented. Previously, `set.rb` added a `SortedSet` autoload, which loads `set/sorted_set.rb`. This replaces the `Set` autoload in `prelude.rb` with a `SortedSet` autoload, but I recommend removing it and `set/sorted_set.rb`. This moves `test/set/test_set.rb` to `test/ruby/test_set.rb`, reflecting that switch to a core class. This does not move the spec files, as I'm not sure how they should be handled. Internally, this uses the st_* types and functions as much as possible, and only adds set_* types and functions as needed. The underlying set_table implementation is stored in st.c, but there is no public C-API for it, nor is there one planned, in order to keep the ability to change the internals going forward. For internal uses of st_table with Qtrue values, those can probably be replaced with set_table. To do that, include internal/set_table.h. To handle symbol visibility (rb_ prefix), internal/set_table.h uses the same macro approach that include/ruby/st.h uses. The Set class (rb_cSet) and all methods are defined in set.c. There isn't currently a C-API for the Set class, though C-API functions can be added as needed going forward. Implements [Feature #21216] Co-authored-by: Jean Boussier <[email protected]> Co-authored-by: Oliver Nutter <[email protected]>
5 daysmaybe fix bindgenAaron Patterson
5 daysDeopt if iseq trace events are enabledAaron Patterson
5 daysAdd parse.y implementationAaron Patterson
5 daysupdate allocation location testsAaron Patterson
5 daysInline Class#new.Aaron Patterson
This commit inlines instructions for Class#new. To make this work, we added a new YARV instructions, `opt_new`. `opt_new` checks whether or not the `new` method is the default allocator method. If it is, it allocates the object, and pushes the instance on the stack. If not, the instruction jumps to the "slow path" method call instructions. Old instructions: ``` > ruby --dump=insns -e'Object.new' == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,10)> 0000 opt_getconstant_path <ic:0 Object> ( 1)[Li] 0002 opt_send_without_block <calldata!mid:new, argc:0, ARGS_SIMPLE> 0004 leave ``` New instructions: ``` > ./miniruby --dump=insns -e'Object.new' == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,10)> 0000 opt_getconstant_path <ic:0 Object> ( 1)[Li] 0002 putnil 0003 swap 0004 opt_new <calldata!mid:new, argc:0, ARGS_SIMPLE>, 11 0007 opt_send_without_block <calldata!mid:initialize, argc:0, FCALL|ARGS_SIMPLE> 0009 jump 14 0011 opt_send_without_block <calldata!mid:new, argc:0, ARGS_SIMPLE> 0013 swap 0014 pop 0015 leave ``` This commit speeds up basic object allocation (`Foo.new`) by 60%, but classes that take keyword parameters see an even bigger benefit because no hash is allocated when instantiating the object (3x to 6x faster). Here is an example that uses `Hash.new(capacity: 0)`: ``` > hyperfine "ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'" "./ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'" Benchmark 1: ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end' Time (mean ± σ): 1.082 s ± 0.004 s [User: 1.074 s, System: 0.008 s] Range (min … max): 1.076 s … 1.088 s 10 runs Benchmark 2: ./ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end' Time (mean ± σ): 627.9 ms ± 3.5 ms [User: 622.7 ms, System: 4.8 ms] Range (min … max): 622.7 ms … 633.2 ms 10 runs Summary ./ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end' ran 1.72 ± 0.01 times faster than ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end' ``` This commit changes the backtrace for `initialize`: ``` aaron@tc ~/g/ruby (inline-new)> cat test.rb class Foo def initialize puts caller end end def hello Foo.new end hello aaron@tc ~/g/ruby (inline-new)> ruby -v test.rb ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24] test.rb:8:in 'Class#new' test.rb:8:in 'Object#hello' test.rb:11:in '<main>' aaron@tc ~/g/ruby (inline-new)> ./miniruby -v test.rb ruby 3.5.0dev (2025-03-28T23:59:40Z inline-new c4157884e4) +PRISM [arm64-darwin24] test.rb:8:in 'Object#hello' test.rb:11:in '<main>' ``` It also increases memory usage for calls to `new` by 122 bytes: ``` aaron@tc ~/g/ruby (inline-new)> cat test.rb require "objspace" class Foo def initialize puts caller end end def hello Foo.new end puts ObjectSpace.memsize_of(RubyVM::InstructionSequence.of(method(:hello))) aaron@tc ~/g/ruby (inline-new)> make runruby RUBY_ON_BUG='gdb -x ./.gdbinit -p' ./miniruby -I./lib -I. -I.ext/common ./tool/runruby.rb --extout=.ext -- --disable-gems ./test.rb 656 aaron@tc ~/g/ruby (inline-new)> ruby -v test.rb ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24] 544 ``` Thanks to @ko1 for coming up with this idea! Co-Authored-By: John Hawthorn <[email protected]>
5 daysZJIT: Bail out of HIR translation if we can't handle a send flag (#13182)Max Bernstein
Bail out of HIR translation if we can't handle a send flag Notes: Merged-By: k0kubun <[email protected]>
5 daysZJIT: Emit CCall if we know the type statically, not just from profiles (#13173)Max Bernstein
Emit CCall if we know the type statically, not just from profiles Notes: Merged-By: k0kubun <[email protected]>
6 daysCount metadata entries automatically from the names listNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/13181
6 daysUpdate `RB_GC_OBJECT_METADATA_ENTRY_COUNT`Jean Boussier
In cb1ea54bbf6cdf49c53f42720fec1a151069810c I added one more metadata flag, but didn't notice `RB_GC_OBJECT_METADATA_ENTRY_COUNT` had to be incremented. This should fix ASAN builds. Interestingly, bdb25959fb047af0358f33d7327b7752dca14aa4 already caused the count to be off by one, so I had to increment it by 2. Notes: Merged: https://github.com/ruby/ruby/pull/13179
6 daysUse OS label for actions/cache. vcpkg only uses same os cacheHiroshi SHIBATA
6 days[rubygems/rubygems] bin/rubocop -a --only Style/StringLiteralsHiroshi SHIBATA
https://github.com/rubygems/rubygems/commit/62e1bf2d37 Notes: Merged: https://github.com/ruby/ruby/pull/13177
6 daysUpdate bundled gems list as of 2025-04-25git
6 daysUse actions/cache instead of vcpkg built-in cache featureHiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/13176
6 daysRevert "Extract windows-11-arm job from windows.yml because it may ignored ↵Hiroshi SHIBATA
vcpkg binary cache for x64-windows" This reverts commit 8e258af5b083a417a8f5e424a2c7d2c4800f8ca2. Notes: Merged: https://github.com/ruby/ruby/pull/13176
6 daysExtract windows-11-arm job from windows.yml because it may ignored vcpkg ↵Hiroshi SHIBATA
binary cache for x64-windows Notes: Merged: https://github.com/ruby/ruby/pull/13174
6 daysUpdate default gems list at 6f336d1b154e608d5200bd8de48473 [ci skip]git
6 days[rubygems/rubygems] Remove shellwords autoloadDavid Rodríguez
https://github.com/rubygems/rubygems/commit/2af1646776
6 days[ruby/json] Release 2.11.2Jean Boussier
https://github.com/ruby/json/commit/c985e8c6ea
6 days[ruby/json] Bring back JSON::PRETTY_STATE_PROTOTYPE with a deprecationJean Boussier
Fix: https://github.com/ruby/json/issues/788 `multi_json` rely on it, even though it was never documented as public API. Bringing it back as a method so it can emit a deprecation warning. https://github.com/ruby/json/commit/123121bba2
6 days[ruby/json] Release 2.11.1Jean Boussier
https://github.com/ruby/json/commit/84443e881d
6 days[ruby/json] Bring back the numerous deprecated aliasJean Boussier
This time with explicit deprecation warnings. https://github.com/ruby/json/commit/0dee9bdad9
6 days[ruby/json] Release 2.11.0Jean Boussier
https://github.com/ruby/json/commit/a6949f8656
6 daysZJIT: Fold Send into SendWithoutBlockDirect if we know the class statically ↵Max Bernstein
(#13172) Fold Send into SendWithoutBlockDirect if we know the class statically This applies for constants and also for values where we know the type for other reasons. Notes: Merged-By: k0kubun <[email protected]>
6 daysAdd testsMax Bernstein
Notes: Merged: https://github.com/ruby/ruby/pull/13162
6 daysMake type_of use union-findMax Bernstein
Otherwise we might have stale types floating around Notes: Merged: https://github.com/ruby/ruby/pull/13162
6 daysMake PatchPoint(CalleeModifiedLocals) implicitMax Bernstein
We don't have a good model for modeling weakref-like instruction dependency behavior and I don't think we should add it just for this. Notes: Merged: https://github.com/ruby/ruby/pull/13162
6 daysStrength reduce sends on Fixnums in the optimizer instead of HIR builderMax Bernstein
Notes: Merged: https://github.com/ruby/ruby/pull/13162
6 daysSimplify fixnum guarding codeMax Bernstein
Notes: Merged: https://github.com/ruby/ruby/pull/13162
6 daysFix tiny typo in syntax/exceptions.rdocMasafumi Koba
Notes: Merged: https://github.com/ruby/ruby/pull/13171
6 daysFix memoization for the `/(...){0}/` case (#13169)Hiroya Fujinami
In this case, the previous implementation counted an extra number of opcodes to cache and the matching was unstable on memoization. This patch is to fix that problem by not counting an number of opcodes to cache in the parentheses of `(...){0}`. Notes: Merged-By: makenowjust <[email protected]>
7 daysFix a flaky test by making sure that a test thread stopsYusuke Endoh
``` 1) Failure: TestThread#test_join_argument_conversion [D:/a/ruby/ruby/src/test/ruby/test_thread.rb:249]: Expected nil (oid=4) to be the same as #<TestThread::Thread:0x000001e9e13bbc18 D:/a/ruby/ruby/src/test/ruby/test_thread.rb:245 run> (oid=3856). ``` https://github.com/ruby/ruby/actions/runs/14636019219/job/41067199813?pr=13169 Notes: Merged: https://github.com/ruby/ruby/pull/13170
7 daysMove VCPKG_BINARY_SOURCES to global environmental variable on workflowHiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/13166
7 daysDo not allocate new objects at machine stack overflowNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/13167
7 daysobjspace_dump: Include `shareable` flagJean Boussier
Given that the currently planned ractor local GC implementation performance will heavilly be influenced by the number of shareable objects it would be valuable to be able to know how many of them are in the heap.
7 daysUpdate bundled gems list as of 2025-04-24git
7 daysAdded --vcpkg-root for fixing mismatched vcpkg root with scoop versionHiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/13165
7 dayscodeql-trap cache is growing over 300MB. We should enable to cleanup ↵Hiroshi SHIBATA
needless cache from actions/cache Notes: Merged: https://github.com/ruby/ruby/pull/13165
7 daysRewrite CGI.parse with URI.decode_www_form_componentHiroshi SHIBATA
Co-authored-by: Nobuyoshi Nakada <[email protected]>
7 daysRemoved unused cgi libraryHiroshi SHIBATA
7 daysUse cgi/util if that uses like CGI.escape methodsHiroshi SHIBATA
7 daysZJIT: Fix README example command (#13163)Aiden Fox Ivey
Fix README example command
7 daysFix comparison of signed and unsigned integersJean Boussier
``` ../string.c:660:38: warning: comparison of integers of different signs: 'rb_atomic_t' (aka 'unsigned int') and 'int' [-Wsign-compare] 660 | RUBY_ASSERT(table->count < table->capacity / 2); ``` Notes: Merged: https://github.com/ruby/ruby/pull/13160
8 daysRun auto-style.rb only on ruby/rubyNobuyoshi Nakada
`github.event.before` for newly pushed branch is all zero and cannot check out. Notes: Merged: https://github.com/ruby/ruby/pull/13158
8 daysEagerly store a copy of `object_id` in finalizer table.Jean Boussier
This makes the finalizer table fully self contained, so GC no longer need to delay cleaning the `obj_to_id_tbl`. Notes: Merged: https://github.com/ruby/ruby/pull/13155
8 daysall of examples at commands/newgem_spec.rb are working on ruby repoHiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/13156
8 daysRemove unexpected files [ci skip]Nobuyoshi Nakada
8 daysCheck Unicode version of the normalization tableNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/13154
8 daysAdd Encoding::UNICODE_VERSION constantNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/13154