fredrikekre / Runic.jl

A code formatter for Julia with rules set in stone.
MIT License
98 stars 3 forks source link

avoid variables captured in closure from becoming boxed by passing them in as arguments. #30

Closed KristofferC closed 2 months ago

KristofferC commented 2 months ago

This is kind of sad...

code_warntype(Runic.spaces_in_listlike, Tuple{Runic.Context, Runic.Node})

showed that

require_trailing_comma::Core.Box
last_item_idx::Core.Box

and this poisoned a bunch of other values they touch to become ::Any.

For verifying the formatting of base/* in the julia repo:

Before:

    1.793848 seconds (42.09 M allocations: 1.342 GiB, 3.55% gc time)

After:

  1.576102 seconds (26.10 M allocations: 1.068 GiB, 3.58% gc time)

The times are kind of variable because it hits the filesystem quite a lot but it allocates around half at least.

fredrikekre commented 2 months ago

Thanks