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

FinField: use concrete types for sub-/overfield morphisms to improve inferrability #1961

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

benlorenz
Copy link
Collaborator

Both functions modifying these dicts already restrict the types in the same way:

function AddOverfield!(F::T, f::FinFieldMorphism{T, T}) where T <: FinField
function AddSubfield!(F::T, f::FinFieldMorphism{T, T}) where T <: FinField

Without this PR:

julia> using Oscar
...
julia> F = finite_field(3)[1]
Prime field of characteristic 3

julia> a = F(0)
0

julia> @time @eval a*a
 48.451252 seconds (221.69 M allocations: 10.308 GiB, 6.01% gc time, 99.98% compilation time: 100% of which was recompilation)
0

(Any further calls will be fast since it is already compiled)

With the changes in this PR:

julia> using Oscar
...
julia> F = finite_field(3)[1]
Prime field of characteristic 3

julia> a = F(0)
0

julia> @time @eval a*a
  0.000158 seconds (56 allocations: 2.203 KiB)
0

Without the changes here the return type of Nemo.domain(::FinFieldMorphism) which is used inside Nemo.intersections(::FinField,::FinField) cannot be inferred. Then the compiler seems to look at all possible embed(Any,Any) functions which takes very long, especially the branch for Hecke.embed(S::ZZLat, G::ZZGenus).

For Nemo alone the difference is less significant, but it does improve allocations during compilation quite a bit.
0.47.5:

julia> @time @eval a*a
  0.806358 seconds (2.61 M allocations: 128.606 MiB, 2.89% gc time, 99.97% compilation time)
0

this PR:

julia> @time @eval a*a
  0.836485 seconds (1.29 M allocations: 63.900 MiB, 1.45% gc time, 99.97% compilation time)
0

cc: @flenzen @thofma @fingolfin

flamegraph for snoop_inference without this PR:

fieldmul_flamegraph

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.93%. Comparing base (578b513) to head (a0b6f9a).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1961      +/-   ##
==========================================
- Coverage   87.96%   87.93%   -0.03%     
==========================================
  Files          99       99              
  Lines       36457    36457              
==========================================
- Hits        32069    32059      -10     
- Misses       4388     4398      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic!

@thofma thofma merged commit e4e5751 into Nemocas:master Dec 5, 2024
23 of 24 checks passed
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.

3 participants