<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ruby.git/test/-ext-/string/test_capacity.rb, branch v3_3_11</title>
<subtitle>The Ruby Programming Language</subtitle>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/'/>
<entry>
<title>String.new(capacity:) don't substract termlen (#11027)</title>
<updated>2024-06-20T17:39:20+00:00</updated>
<author>
<name>Jean byroot Boussier</name>
<email>jean.boussier+github@shopify.com</email>
</author>
<published>2024-06-20T17:39:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=d1ffd5ecfa62a049b7c508f30b6912a890de1b32'/>
<id>d1ffd5ecfa62a049b7c508f30b6912a890de1b32</id>
<content type='text'>
[Bug #20585]

This was changed in 36a06efdd9f0604093dccbaf96d4e2cb17874dc8 because
`String.new(1024)` would end up allocating `1025` bytes, but the problem
with this change is that the caller may be trying to right size a String.

So instead, we should just better document the behavior of `capacity:`.

Co-authored-by: Jean Boussier &lt;jean.boussier@gmail.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[Bug #20585]

This was changed in 36a06efdd9f0604093dccbaf96d4e2cb17874dc8 because
`String.new(1024)` would end up allocating `1025` bytes, but the problem
with this change is that the caller may be trying to right size a String.

So instead, we should just better document the behavior of `capacity:`.

Co-authored-by: Jean Boussier &lt;jean.boussier@gmail.com&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>Make String.new size pools aware.</title>
<updated>2023-11-02T22:34:58+00:00</updated>
<author>
<name>Jean Boussier</name>
<email>byroot@ruby-lang.org</email>
</author>
<published>2023-11-02T10:02:43+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=ac8ec004e5272d589caca30616dbe12862150188'/>
<id>ac8ec004e5272d589caca30616dbe12862150188</id>
<content type='text'>
If the required capacity would fit in an embded string,
returns one.

This can reduce malloc churn for code that use string buffers.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
If the required capacity would fit in an embded string,
returns one.

This can reduce malloc churn for code that use string buffers.
</pre>
</div>
</content>
</entry>
<entry>
<title>Unify length field for embedded and heap strings  (#7908)</title>
<updated>2023-06-06T14:19:20+00:00</updated>
<author>
<name>Peter Zhu</name>
<email>peter@peterzhu.ca</email>
</author>
<published>2023-06-06T14:19:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=7577c101ed6452de3e72fadb43db595946acc701'/>
<id>7577c101ed6452de3e72fadb43db595946acc701</id>
<content type='text'>
* Unify length field for embedded and heap strings

The length field is of the same type and position in RString for both
embedded and heap allocated strings, so we can unify it.

* Remove RSTRING_EMBED_LEN</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* Unify length field for embedded and heap strings

The length field is of the same type and position in RString for both
embedded and heap allocated strings, so we can unify it.

* Remove RSTRING_EMBED_LEN</pre>
</div>
</content>
</entry>
<entry>
<title>[Feature #19579] Remove !USE_RVARGC code (#7655)</title>
<updated>2023-04-04T21:30:06+00:00</updated>
<author>
<name>Peter Zhu</name>
<email>peter@peterzhu.ca</email>
</author>
<published>2023-04-04T21:30:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=1da2e7fca35dc697d85dd91d2572ab58d08cd3bc'/>
<id>1da2e7fca35dc697d85dd91d2572ab58d08cd3bc</id>
<content type='text'>
Remove !USE_RVARGC code

[Feature #19579]

The Variable Width Allocation feature was turned on by default in Ruby
3.2. Since then, we haven't received bug reports or backports to the
non-Variable Width Allocation code paths, so we assume that nobody is
using it. We also don't plan on maintaining the non-Variable Width
Allocation code, so we are going to remove it.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Remove !USE_RVARGC code

[Feature #19579]

The Variable Width Allocation feature was turned on by default in Ruby
3.2. Since then, we haven't received bug reports or backports to the
non-Variable Width Allocation code paths, so we assume that nobody is
using it. We also don't plan on maintaining the non-Variable Width
Allocation code, so we are going to remove it.</pre>
</div>
</content>
</entry>
<entry>
<title>Decouple GC slot sizes from RVALUE</title>
<updated>2022-02-02T14:52:04+00:00</updated>
<author>
<name>Peter Zhu</name>
<email>peter@peterzhu.ca</email>
</author>
<published>2022-02-01T14:25:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=7b77d46671685c837adc33b39ae0210e04cd8b24'/>
<id>7b77d46671685c837adc33b39ae0210e04cd8b24</id>
<content type='text'>
Add a new macro BASE_SLOT_SIZE that determines the slot size.

For Variable Width Allocation (compiled with USE_RVARGC=1), all slot
sizes are powers-of-2 multiples of BASE_SLOT_SIZE.

For USE_RVARGC=0, BASE_SLOT_SIZE is set to sizeof(RVALUE).
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Add a new macro BASE_SLOT_SIZE that determines the slot size.

For Variable Width Allocation (compiled with USE_RVARGC=1), all slot
sizes are powers-of-2 multiples of BASE_SLOT_SIZE.

For USE_RVARGC=0, BASE_SLOT_SIZE is set to sizeof(RVALUE).
</pre>
</div>
</content>
</entry>
<entry>
<title>Make embedded string length a long for VWA</title>
<updated>2022-01-12T17:00:55+00:00</updated>
<author>
<name>Peter Zhu</name>
<email>peter@peterzhu.ca</email>
</author>
<published>2022-01-11T20:19:39+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=2d81a718eca679b9bf458beccf1e7a86b812c3e2'/>
<id>2d81a718eca679b9bf458beccf1e7a86b812c3e2</id>
<content type='text'>
A short (2 bytes) will cause unaligned struct accesses when strings are
used as a buffer to directly store binary data.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
A short (2 bytes) will cause unaligned struct accesses when strings are
used as a buffer to directly store binary data.
</pre>
</div>
</content>
</entry>
<entry>
<title>[Feature #18239] Implement VWA for strings</title>
<updated>2021-10-25T17:26:23+00:00</updated>
<author>
<name>Peter Zhu</name>
<email>peter@peterzhu.ca</email>
</author>
<published>2021-08-26T14:06:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=a5b6598192c30187b19b892af3110a46f6a70d76'/>
<id>a5b6598192c30187b19b892af3110a46f6a70d76</id>
<content type='text'>
This commit adds support for embedded strings with variable capacity and
uses Variable Width Allocation to allocate strings.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This commit adds support for embedded strings with variable capacity and
uses Variable Width Allocation to allocate strings.
</pre>
</div>
</content>
</entry>
<entry>
<title>Revert "[EXPERIMENTAL] Make Symbol#to_s return a frozen String [Feature #16150]"</title>
<updated>2019-11-05T08:30:54+00:00</updated>
<author>
<name>NARUSE, Yui</name>
<email>naruse@airemix.jp</email>
</author>
<published>2019-11-05T08:30:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=bea322a352d820007dd4e6cab88af5de01854736'/>
<id>bea322a352d820007dd4e6cab88af5de01854736</id>
<content type='text'>
This reverts commit 6ffc045a817fbdf04a6945d3c260b55b0fa1fd1e.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This reverts commit 6ffc045a817fbdf04a6945d3c260b55b0fa1fd1e.
</pre>
</div>
</content>
</entry>
<entry>
<title>[EXPERIMENTAL] Make Symbol#to_s return a frozen String</title>
<updated>2019-09-26T08:23:02+00:00</updated>
<author>
<name>Benoit Daloze</name>
<email>eregontp@gmail.com</email>
</author>
<published>2019-09-08T09:53:27+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=6ffc045a817fbdf04a6945d3c260b55b0fa1fd1e'/>
<id>6ffc045a817fbdf04a6945d3c260b55b0fa1fd1e</id>
<content type='text'>
* Always the same frozen String for a given Symbol.
* Avoids extra allocations whenever calling Symbol#to_s.
* See [Feature #16150]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* Always the same frozen String for a given Symbol.
* Avoids extra allocations whenever calling Symbol#to_s.
* See [Feature #16150]
</pre>
</div>
</content>
</entry>
<entry>
<title>Resize capacity for fstring</title>
<updated>2019-06-26T06:01:48+00:00</updated>
<author>
<name>John Hawthorn</name>
<email>john@hawthorn.email</email>
</author>
<published>2019-06-25T16:01:57+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=04bc4c0662344238a556aa92f5f8f6d42586bab3'/>
<id>04bc4c0662344238a556aa92f5f8f6d42586bab3</id>
<content type='text'>
When a string is #frozen, it's capacity is resized to fit (if it is much
larger), since we know it will no longer be mutated.

    &gt; puts ObjectSpace.dump(String.new("a"*30, capacity: 1000))
    {"type":"STRING", "class":"0x7feaf00b7bf0", "bytesize":30, "capacity":1000, "value":"...
    &gt; puts ObjectSpace.dump(String.new("a"*30, capacity: 1000).freeze)
    {"type":"STRING", "class":"0x7feaf00b7bf0", "frozen":true, "bytesize":30, "value":"...

(ObjectSpace.dump doesn't show capacity if capacity is equal to bytesize)

Previously, if we dedup into an fstring, using String#-@, capacity would
not be reduced.

    &gt; puts ObjectSpace.dump(-String.new("a"*30, capacity: 1000))
    {"type":"STRING", "class":"0x7feaf00b7bf0", "frozen":true, "fstring":true, "bytesize":30, "capacity":1000, "value":"...

This commit makes rb_fstring call rb_str_resize, the same as
rb_str_freeze does.

Closes: https://github.com/ruby/ruby/pull/2256
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When a string is #frozen, it's capacity is resized to fit (if it is much
larger), since we know it will no longer be mutated.

    &gt; puts ObjectSpace.dump(String.new("a"*30, capacity: 1000))
    {"type":"STRING", "class":"0x7feaf00b7bf0", "bytesize":30, "capacity":1000, "value":"...
    &gt; puts ObjectSpace.dump(String.new("a"*30, capacity: 1000).freeze)
    {"type":"STRING", "class":"0x7feaf00b7bf0", "frozen":true, "bytesize":30, "value":"...

(ObjectSpace.dump doesn't show capacity if capacity is equal to bytesize)

Previously, if we dedup into an fstring, using String#-@, capacity would
not be reduced.

    &gt; puts ObjectSpace.dump(-String.new("a"*30, capacity: 1000))
    {"type":"STRING", "class":"0x7feaf00b7bf0", "frozen":true, "fstring":true, "bytesize":30, "capacity":1000, "value":"...

This commit makes rb_fstring call rb_str_resize, the same as
rb_str_freeze does.

Closes: https://github.com/ruby/ruby/pull/2256
</pre>
</div>
</content>
</entry>
</feed>
