xod icon indicating copy to clipboard operation
xod copied to clipboard

Make `format-number` lazy

Open nkrkv opened this issue 7 years ago • 0 comments

Rationale

Currently, format-number and the implicit number-to-string cast allocates a 16-byte array to hold the result. The buffer is allocated in global RAM, so each cast and each format-number permanently uses 23 bytes of RAM. We can do formatting more efficient by dealing with strings only right at the moment of enumeration.

It will save at least 12 bytes of RAM per node/cast.

How to optimize

Make a new string view FortmattedNumberView which will store the number as Number to format. That view should make it own iterator implementation. The iterator is responsible for allocating the buffer and formatting to string.

Using this technique a required buffer will be always allocated on the stack and only kept alive for the (short) lifetime of an iterator.

Acceptance criteria

  • [ ] format-number uses the described technique
  • [ ] cast-to-string(number) uses the technique

nkrkv avatar Jul 06 '18 15:07 nkrkv