Skip to content

Bug: self parameter increases heap usage #5767

@timohanke

Description

@timohanke

Uses "normal" heap amount (or no heap):

  • Region.loadNat64(region, ..) from core 1.0.0
  • Prim.regionLoadNat64(region, ..)

Uses higher heap amount:

  • Region.loadNat64(region, ..) from core 2.0.0
  • region.loadNat64(..) notation with core 2.0.0

The only difference between the two is that the first parameter of Region.loadNat64in core 2.0.0 is named self. Everything else is the same.

Note: This happens only for loadNat64, not for loadBlob.

To reproduce:
Check out this branch: https://github.com/research-ag/stable-trie/tree/optimize
Run mops bench main and you will see:

Garbage Collection

|    |        2 |        4 |       16 |      256 |
| :- | -------: | -------: | -------: | -------: |
| 0  |    440 B |    440 B |    440 B |    440 B |
| 1  |    484 B |    468 B |    468 B |    468 B |
| 2  |    512 B |    512 B |    496 B |    496 B |
| 3  |    600 B |    584 B |    568 B |    552 B |
| 4  |    744 B |    744 B |    728 B |    664 B |
| 5  | 1.04 KiB | 1.01 KiB |    968 B |    888 B |
| 6  | 1.65 KiB | 1.52 KiB | 1.48 KiB | 1.41 KiB |
| 7  | 2.91 KiB | 2.84 KiB | 2.51 KiB | 2.48 KiB |
| 8  | 5.41 KiB | 4.96 KiB | 4.68 KiB | 4.62 KiB |

Then go to here (UPDATED):
https://github.com/research-ag/stable-trie/blob/abb60a0eab1ef1c02c0f84b1fab802a8462d6248/src/base.mo#L248
and replace this line

Prim.regionLoadNat64(region, getNodeOffset(node, index)) & loadMask;

with

Region.loadNat64(region, getNodeOffset(node, index)) & loadMask;

Run mops bench main again and you will see:

Garbage Collection

|    |         2 |         4 |       16 |      256 |
| :- | --------: | --------: | -------: | -------: |
| 0  |     440 B |     440 B |    440 B |    440 B |
| 1  |     484 B |     468 B |    468 B |    468 B |
| 2  |     560 B |     512 B |    496 B |    496 B |
| 3  |     672 B |     632 B |    580 B |    552 B |
| 4  |   1.1 KiB |     924 B |    764 B |    700 B |
| 5  |  1.82 KiB |  1.44 KiB | 1.11 KiB |    912 B |
| 6  |  3.64 KiB |  2.58 KiB | 1.86 KiB | 1.51 KiB |
| 7  |  7.64 KiB |  5.27 KiB | 3.57 KiB | 2.88 KiB |
| 8  | 16.43 KiB | 10.66 KiB | 7.33 KiB | 5.85 KiB |

To try core 1.0.0 you have to go back a few commits and check out 2d1a6e35c6a01b919acb009e22adffad62b70b41. Then change to core "1.0.0" in mops.toml and run mops bench main again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions