1lab/mikan
13
52
Fork
You've already forked mikan
9

Remove -fexpose-all-unfoldings and -fspecialise-aggressively #69

Open
opened 2026年04月30日 18:35:40 +02:00 by totbwf · 2 comments

Enabling these flags makes the build way slower and can really bloat the binary size with useless specializations. This bloat can also cause performance issues, as we end up with more icache misses.

To this end, we should isolate the functions that actually need specialization, and mark them with SPECIALIZE pragmas.

Enabling these flags makes the build *way* slower and can really bloat the binary size with useless specializations. This bloat can also cause performance issues, as we end up with more icache misses. To this end, we should isolate the functions that actually need specialization, and mark them with `SPECIALIZE` pragmas.
Author
Owner
Copy link

Some relevant stats

-optimise-heavily

on my machine, 8e930b5e51 with -optimise-heavily +debug takes ~13min to compile, and allocates 740gb while doing so; full report generated by https://github.com/codedownio/time-ghc-modules linked below. The resulting binary is 142m. Stats for checking the 1lab are:

1,654,370,034,040 bytes allocated in the heap
 160,555,604,768 bytes copied during GC
 2,463,677,992 bytes maximum residency (133 sample(s))
 4,817,896 bytes maximum slop
 4707 MiB total memory in use (0 MiB lost due to fragmentation)
 Tot time (elapsed) Avg pause Max pause
 Gen 0 395052 colls, 0 par 74.991s 76.062s 0.0002s 0.0034s
 Gen 1 133 colls, 0 par 4.790s 5.209s 0.0392s 0.2543s
 TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)
 SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)
 INIT time 0.002s ( 0.002s elapsed)
 MUT time 274.165s (273.487s elapsed)
 GC time 79.781s ( 81.270s elapsed)
 EXIT time 0.187s ( 0.010s elapsed)
 Total time 354.135s (354.769s elapsed)
 Alloc rate 6,034,214,440 bytes per MUT second
 Productivity 77.4% of total user, 77.1% of total elapsed

+optimise-heavily

Conversely, a build with +optimise-heavily +debug takes ~16 minutes to typecheck while allocating 995gb of memory, and results in a 172m binary. Stats for checking the 1lab:

 898,004,982,600 bytes allocated in the heap
 126,166,773,328 bytes copied during GC
 2,455,545,752 bytes maximum residency (118 sample(s))
 4,801,968 bytes maximum slop
 4770 MiB total memory in use (0 MiB lost due to fragmentation)
 Tot time (elapsed) Avg pause Max pause
 Gen 0 213999 colls, 0 par 58.785s 61.142s 0.0003s 0.0083s
 Gen 1 118 colls, 0 par 4.144s 5.083s 0.0431s 0.5015s
 TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)
 SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)
 INIT time 0.003s ( 0.003s elapsed)
 MUT time 156.325s (154.849s elapsed)
 GC time 62.929s ( 66.225s elapsed)
 EXIT time 0.379s ( 0.013s elapsed)
 Total time 219.636s (221.090s elapsed)
 Alloc rate 5,744,468,220 bytes per MUT second
 Productivity 71.2% of total user, 70.0% of total elapsed
Some relevant stats ## `-optimise-heavily` on my machine, 8e930b5e51 with -optimise-heavily +debug takes ~13min to compile, and allocates 740gb while doing so; full report generated by https://github.com/codedownio/time-ghc-modules linked below. The resulting binary is 142m. Stats for checking the 1lab are: ``` 1,654,370,034,040 bytes allocated in the heap 160,555,604,768 bytes copied during GC 2,463,677,992 bytes maximum residency (133 sample(s)) 4,817,896 bytes maximum slop 4707 MiB total memory in use (0 MiB lost due to fragmentation) Tot time (elapsed) Avg pause Max pause Gen 0 395052 colls, 0 par 74.991s 76.062s 0.0002s 0.0034s Gen 1 133 colls, 0 par 4.790s 5.209s 0.0392s 0.2543s TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1) SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled) INIT time 0.002s ( 0.002s elapsed) MUT time 274.165s (273.487s elapsed) GC time 79.781s ( 81.270s elapsed) EXIT time 0.187s ( 0.010s elapsed) Total time 354.135s (354.769s elapsed) Alloc rate 6,034,214,440 bytes per MUT second Productivity 77.4% of total user, 77.1% of total elapsed ``` ## `+optimise-heavily` Conversely, a build with +optimise-heavily +debug takes ~16 minutes to typecheck while allocating 995gb of memory, and results in a 172m binary. Stats for checking the 1lab: ``` 898,004,982,600 bytes allocated in the heap 126,166,773,328 bytes copied during GC 2,455,545,752 bytes maximum residency (118 sample(s)) 4,801,968 bytes maximum slop 4770 MiB total memory in use (0 MiB lost due to fragmentation) Tot time (elapsed) Avg pause Max pause Gen 0 213999 colls, 0 par 58.785s 61.142s 0.0003s 0.0083s Gen 1 118 colls, 0 par 4.144s 5.083s 0.0431s 0.5015s TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1) SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled) INIT time 0.003s ( 0.003s elapsed) MUT time 156.325s (154.849s elapsed) GC time 62.929s ( 66.225s elapsed) EXIT time 0.379s ( 0.013s elapsed) Total time 219.636s (221.090s elapsed) Alloc rate 5,744,468,220 bytes per MUT second Productivity 71.2% of total user, 70.0% of total elapsed ```

To reduce binary sizes, independently of opt flags, you could try to use -split-sections on everything (including dependencies but I don't know ATM how to configure that outside of Stack).

To reduce binary sizes, independently of opt flags, you could try to use `-split-sections` on everything (including dependencies but I don't know ATM how to configure that outside of Stack).
Sign in to join this conversation.
No Branch/Tag specified
main
aliao/occurs-opt
aliao/rec-con
fix-license
aliao/oopsie
aliao/strengthen-iapply
No results found.
Labels
Clear labels
1 - scope
language
Backwards-compatible changes to the surface language, such as adding new features.
1 - scope
language change
Breaking changes to a documented part of the surface language. These should be documented and specifically called out in the changelog.
1 - scope
performance
Semantics-preserving performance work.
1 - scope
task
Changes that are not apparent to the user, e.g. developer documentation and refactors, which do not need to be documented.
A: dead-code
Dead code elimination and --save-metas.
A: errors
Reporting of error and warning messages.
A: highlighting
Highlighting during interaction & literate compilation
A: imports
Handling of imports and interface file de/serialization.
A: infra
Iinfrastructure (e.g. CI, developer documentation, the build system, or the repository itself)
A: instance
Instance declarations, arguments, and resolution
A: lhs
LHS checking, coverage checking, and clause compilation
A: modules
Declaration and instantiation of parametrised modules.
A: parallel
Parallel typechecking.
A: positivity
Positivity checking
A: printing
Pretty-printing, display forms, and the wording of diagnostic messages
A: records
Record declarations, record expressions and copattern matching
A: scoping
Scope checking (ConcreteToAbstract)
A: termination
Termination checking
0 - type
bug
Issues describing an incorrect behaviour in the project, typos in the documentation, etc.
0 - type
discussion
An issue raised to gather opinions on a proposed change, or a suggested language change.
0 - type
question
An issue raised to ask a question.
9 - status
duplicate
This issue or pull request already exists.
9 - status
info needed
More information is needed from the submitter to decide how to proceed with the issue report.
9 - status
invalid
The issue report or pull request does not describe an actual bug, or does otherwise does not meet the contributing guidelines.
good first issue
Interested in contributing? Get started here.
upstream
Related to an upstream repository, already reported there
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
1lab/mikan#69
Reference in a new issue
1lab/mikan
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?