Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compactify storage #20

Merged
merged 12 commits into from
Apr 3, 2023
Merged

Compactify storage #20

merged 12 commits into from
Apr 3, 2023

Conversation

MasonProtter
Copy link
Owner

@MasonProtter MasonProtter commented Apr 3, 2023

This makes SumTypes smaller. They should now only take up however much room the largest variant needed, plus a discriminator byte, plus alignment bits.

julia> @sum_type Num begin
           Int(::Int)
           Float(::Float64)
           Complex(::Float64,::Float64)
       end hide_variants=true;

before

julia> sizeof(full_type(Num))
56

After

julia> sizeof(full_type(Num))
24

Downside is that the sum types now have extra type parameters relating to the computed storage. They could be eliminated for sum types without parameters, but in general they're necessary unless we get JuliaLang/julia#8472 (comment).

@codecov
Copy link

codecov bot commented Apr 3, 2023

Codecov Report

Merging #20 (a0796be) into master (b0423ba) will increase coverage by 0.81%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           master       #20      +/-   ##
===========================================
+ Coverage   99.18%   100.00%   +0.81%     
===========================================
  Files           3         4       +1     
  Lines         245       307      +62     
===========================================
+ Hits          243       307      +64     
+ Misses          2         0       -2     
Impacted Files Coverage Δ
src/cases.jl 100.00% <ø> (ø)
src/SumTypes.jl 100.00% <100.00%> (ø)
src/compute_storage.jl 100.00% <100.00%> (ø)
src/sum_type.jl 100.00% <100.00%> (+1.20%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@MasonProtter MasonProtter merged commit 297b2ac into master Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant