roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
3.86k stars 284 forks source link

Optimize literal list construction in LLVM backend #6832

Open ayazhafiz opened 1 week ago

ayazhafiz commented 1 week ago

Currently, list literals are always heap-allocated and their elements are stored by emitting a GEP and store for each item in the literal. This produces huge quantities of IR, causing compile times for e.g. programs with large literals or ingested files to blow up.

Instead, if a list literal consists entirely of literal values, create a global section for the literal and return a pointer to it.

lukewilliamboswell commented 1 week ago

Tested this using roc-htmx-playground, massive speed up in compile time, and significantly smaller LLVM IR file produced.