CakeML / CakeML/cakeml

lift and deduplicate constants

Open
#803 4 comments 0 reactions 1 assignee Claimed by @myreen View on GitHub
code size enhancement medium effort medium reward performance
Dominant language
Standard ML
Stars
1.2k
Forks
104
Avg merge
2d 21h
Merged PRs (30d)
16

Description

(descoped from #773)

Given a potentially hot function, we should not allocate data in the function which is known to be constant.

Define a "deep constant" to be a closLang expression consisting entirely of Const (integers), String, WordFromInt, and Cons (i.e. all children of a deep constant must be deep constants). Define a "nontrivial maximal deep constant" to be a deep constant which is not contained in a larger deep constant and which requires allocation (is not a Cons with 0 children or a Const in fixnum range.

The (symbols PR) compiler has:
* 57 nontrivial maximal Const, 5 unique
* 3336 nontrivial maximal Cons, 2058 unique
* 866 nontrivial maximal String, 589 unique
* 2254 nontrivial maximal WordFromInt, 121 unique

Total: 2773 unique liftable constants used 6513 times. Of the constants used more than once, there are 624 unique constants; the largest duplicated constant has 39 subobjects (it appears to be related to the initial type environment), and only 697/3740 duplicated constants involve more than one heap object.

Doing only lifting would be a performance improvement but a code size regression since each lifted constant needs to be allocated a global, stored, and loaded (20+ instructions currently, 4 after #797). With deduplication as well this will be marginal currently and a noticeable win with #797.

With the current setup of the semantics this has to be done in closLang as later stages represent strings non-anonymously.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.