Skip to content

Only define the type name table in the main LLVM module#16260

Merged
straight-shoota merged 3 commits intocrystal-lang:masterfrom
HertzDevil:bug/type-id-to-class-name-map-global
Oct 25, 2025
Merged

Only define the type name table in the main LLVM module#16260
straight-shoota merged 3 commits intocrystal-lang:masterfrom
HertzDevil:bug/type-id-to-class-name-map-global

Conversation

@HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Oct 23, 2025

#15904 made every LLVM module that references the #as pseudo-method define its own copy of __crystal_type_id_to_class_name_map, when only one copy in the main LLVM module is sufficient. This PR brings the total cache size of the compiler itself from 234 MB to 148 MB on my Windows machine, for example.

@HertzDevil HertzDevil added performance topic:compiler:codegen kind:regression Something that used to correctly work but no longer works labels Oct 23, 2025
@straight-shoota straight-shoota added this to the 1.19.0 milestone Oct 23, 2025
@miry
Copy link
Contributor

miry commented Oct 23, 2025

TLDR: Thank you very much, @HertzDevil — it works on my machine! 🎉

Since v1.17.0, GHA could no longer compile my application — same for nightly builds.
Locally, I also noticed performance degradation, especially after clearing the cache or using --release.

The last stable version that worked fine is v1.16.3:

  • Cache folder: 428 MB
  • Build time without cache: 4:50 min
  • Build time with cache: 1:35 min

I built Crystal 1.17.0 with LLVM 20 and saw much higher disk writes and memory usage.
Swap grew from 0 GB to 8 GB (I have 16 GB RAM).

  • Cache folder: 1.4 GB
  • Build time without cache: 6:35 min
  • Build time with cache: 5:44 min

The amount of files in the cache folder (~8800) did not change,
but most files increased in size from around 200 KB to 2 MB.

This PR significantly improves the stats:

  • Cach folder: 426 MB 🎉
  • Build time without cache: 3:30 min
  • Build time with cache: 1:30 min

Amazing work by @HertzDevil — super fast at finding and fixing the issue! 🙌


My learning section from @HertzDevil:

  1. llvm-dis makes bs files human-readable:

    llvm-dis M-arten5858D-B-58-01956c356b7343c30982cb67961c1e27.o0.bc -o - > v1.17.0_dis.txt
    
  2. Using diff helps spot codegen changes, e.g.:

     < @"'str'.10876" = private constant ... c"Tuple(Array(AllowlistedJWT), Array(AllowlistedJWT)).class\00"
     < @"'str'.10877" = private constant ... c"Tuple(AllowlistedJWT, Bool | Float32 | Float64 | ...).class\00"

for me, AllowlistedJWT occurrence count jumped from 25 → 115.

@straight-shoota straight-shoota merged commit 0c5737a into crystal-lang:master Oct 25, 2025
49 checks passed
@HertzDevil HertzDevil deleted the bug/type-id-to-class-name-map-global branch October 26, 2025 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:regression Something that used to correctly work but no longer works performance topic:compiler:codegen

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants