bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#70784: Abolish string resizing


From: Mattias Engdegård
Subject: bug#70784: Abolish string resizing
Date: Sun, 5 May 2024 14:33:51 +0200

The Elisp ability to resize strings is high-cost, low-benefit, so we should 
abolish it.

Strings are performance-critical, and the split allocation (fixed-size metadata 
+ variable-size data) and its indirections are not free. This is one reason why 
strings are comparatively expensive in Elisp compared to other languages.

With MPS there is even no use for the special-purpose string data defragger in 
the current GC.

String resizing occurs in exactly one place: `aset` on strings, and then only 
when the mutation alters the string size, in either of two cases:

* When a unibyte string byte is set to a non-byte value (> 255), which also 
forces the string to become multibyte.
* When a multibyte string char is set to a char of different length.

String mutation itself is very rare these days, and resizing string mutation 
exceptionally so.

Best and simplest would be to just turn resizing `aset` on strings into an 
error now. As an alternative, we could start warning about it now and make it 
an error in the next release. The (trivial) patches exist.

Note that this is not a proposal for abolishing string mutation in general. For 
example, `clear-string` would still work on any string, as would arbitrary 
closed mutations on unibyte strings and on ASCII multibyte strings.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]