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

Fix slow show(grid) #599

Merged
merged 1 commit into from
Feb 20, 2023
Merged

Fix slow show(grid) #599

merged 1 commit into from
Feb 20, 2023

Conversation

KnutAM
Copy link
Member

@KnutAM KnutAM commented Feb 10, 2023

The use of repr on every cell in #570 was very slow.
With this PR, there is still performance regression for mixed grids (factor 3), but still ok (in my opinion).

@fredrikekre: Is there a better way to get each type in the union? In that case the suggestion below might make sense, even though I don't think it matters that much...

@codecov-commenter
Copy link

codecov-commenter commented Feb 10, 2023

Codecov Report

Base: 92.79% // Head: 92.77% // Decreases project coverage by -0.03% ⚠️

Coverage data is based on head (da02f53) compared to base (930887e).
Patch coverage: 66.66% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #599      +/-   ##
==========================================
- Coverage   92.79%   92.77%   -0.03%     
==========================================
  Files          28       28              
  Lines        4222     4224       +2     
==========================================
+ Hits         3918     3919       +1     
- Misses        304      305       +1     
Impacted Files Coverage Δ
src/Grid/grid.jl 87.16% <66.66%> (-0.23%) ⬇️

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

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@fredrikekre
Copy link
Member

If you create the Set with types instead of strings it seems pretty ok:

julia> @time sort!(collect(Set(repr(typeof(x)) for x in grid.cells)))
110.462024 seconds (44.03 M allocations: 17.203 GiB, 1.71% gc time, 0.03% compilation time)
1-element Vector{String}:
 "Triangle"

julia> @time collect(Set(typeof(x) for x in grid.cells))
  0.378749 seconds (247.76 k allocations: 51.872 MiB, 5.09% gc time, 35.21% compilation time)
1-element Vector{DataType}:
 Triangle (alias for Cell{2, 3, 3})

@KnutAM
Copy link
Member Author

KnutAM commented Feb 10, 2023

Exactly, that's where I got the 3x (actually 5x for this timing) slowdown from though:

oldversion(grid) = sort!(collect(Set(celltypes[typeof(x)] for x in grid.cells)))
newversion(grid) = sort!(repr.(Set(typeof(x) for x in grid.cells)))
masterversion(grid) = sort!(collect(Set(repr(typeof(x)) for x in grid.cells)))
grid = generate_grid(Triangle, (100, 100));
@time newversion(grid);
  0.002467 seconds (34 allocations: 298.586 KiB)
 @time oldversion(grid);
  0.000490 seconds (9 allocations: 288.680 KiB)
@time masterversion(grid);
  0.921047 seconds (480.01 k allocations: 192.543 MiB, 3.66% gc time

(Timing after a first run for compilation and I have defined the const celltypes=Dict from the previous Ferrite version)

@fredrikekre fredrikekre merged commit 9ce3367 into master Feb 20, 2023
@fredrikekre fredrikekre deleted the kam/fastshow branch February 20, 2023 13:17
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.

None yet

3 participants