Skip to content

Make BigDecimal object embedded#507

Merged
tompng merged 1 commit intoruby:masterfrom
byroot:embedded
Mar 30, 2026
Merged

Make BigDecimal object embedded#507
tompng merged 1 commit intoruby:masterfrom
byroot:embedded

Conversation

@byroot
Copy link
Copy Markdown
Member

@byroot byroot commented Mar 29, 2026

Fix: #293

BigDecimal is a very good fit for embedded objects, as most of them are small, and they're all immutable, so they don't need any resizing.

In most case it results in smaller objects, but also reduces pointer chasing as well as make these objects faster to free for the GC.

master:

>> ObjectSpace.memsize_of(BigDecimal("422343434234234234234234234234423"))
=> 92
>> ObjectSpace.memsize_of(BigDecimal("4223434342342342342342342342344232342423423"))
=> 96

This branch:

>> ObjectSpace.memsize_of(BigDecimal("422343434234234234234234234234423"))
=> 80
>> ObjectSpace.memsize_of(BigDecimal("4223434342342342342342342342344232342423423"))
=> 160

Fix: ruby#293

BigDecimal is a very good fit for embedded objects, as most of
them are small, and they're all immutable, so they don't need
any resizing.

In most case it results in smaller objects, but also reduces pointer
chasing as well as make these objects faster to free for the GC.

master:

```ruby
>> ObjectSpace.memsize_of(BigDecimal("422343434234234234234234234234423"))
=> 92
>> ObjectSpace.memsize_of(BigDecimal("4223434342342342342342342342344232342423423"))
=> 96
```

This branch:

```ruby
>> ObjectSpace.memsize_of(BigDecimal("422343434234234234234234234234423"))
=> 80
>> ObjectSpace.memsize_of(BigDecimal("4223434342342342342342342342344232342423423"))
=> 160
```
Copy link
Copy Markdown
Member

@tompng tompng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Thank you 👍

@tompng tompng merged commit bf04ad4 into ruby:master Mar 30, 2026
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use RUBY_TYPED_EMBEDDABLE in BigDecimal

2 participants