google-research / google-research/dex-lang

Optimize sum-type storage

Open
#415 1 comment 1 reaction 0 assignees View on GitHub
backend / optimization shovel-ready
Dominant language
Haskell
Stars
1.7k
Forks
116
PR merge metrics
No merged PRs in 30d

Description

Right now, when we lower sum types they (roughly) get expanded into a flattened product of all fields appearing in all cases, with only the storage corresponding to the active case actually getting initialized and used at run-time.

But this approach is highly wasteful! In particular an ADT such as
```hs
data ColorfulFloat =
RedFloat Float
BlueFloat Float
GreenFloat Float
```
should only use 5 (1+4) bytes of storage, not 13 (1+4+4+4)!

To improve this situation, we need to modify the Imp codegen to reuse storage already allocated for other cases while emitting the destinations for sum types.

Contributor guide

Open the contributing guide

Research direction

Start by reading the Imp codegen path that emits destinations for sum types, then trace how storage is allocated for each case. The work is complete when inactive case fields no longer add separate storage and an example such as ColorfulFloat uses shared storage for its cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.