summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
authordavidot <davidot@serenityos.org>2022-02-25 01:26:52 +0100
committerAndreas Kling <kling@serenityos.org>2022-08-15 17:11:25 +0200
commite746360b9a0e70cd1f66ca2a1af3f69ed21aceba (patch)
treedfbd82549e2c8b463278ec225f007011d6317fc1 /Userland/Libraries/LibGUI
parent6c504e2bff170cea266765946c6a24d4a5615b08 (diff)
downloadserenity-e746360b9a0e70cd1f66ca2a1af3f69ed21aceba.zip
LibJS: Use NaN boxing to decrease the memory size of Values
Using the fact that there are 2^52-2 NaN representations we can "NaN-box" all the Values possible. This means that Value no longer has an explicit "Type" but that information is now stored in the bits of a double. This is done by "tagging" the top two bytes of the double. For a full explanation see the large comment with asserts at the top of Value. We can also use the exact representation of the tags to make checking properties like nullish, or is_cell quicker. But the largest gains are in the fact that the size of a Value is now halved. The SunSpider and other benchmarks have been ran to confirm that there are no regressions in performance compared to the previous implementation. The tests never performed worse and in some cases performed better. But the biggest differences can be seen in memory usage when large arrays are allocated. A simple test which allocates a 1000 arrays of size 100000 has roughly half the memory usage. There is also space in the representations for future expansions such as tuples and records. To ensure that Values on the stack and registers are not lost during garbage collection we also have to add a check to the Heap to check for any of the cell tags and extracting the canonical form of the pointer if it matches.
Diffstat (limited to 'Userland/Libraries/LibGUI')
0 files changed, 0 insertions, 0 deletions