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

refactor(core): improve grid building routines #209

Merged
merged 8 commits into from
Oct 28, 2024
Merged

Conversation

imrn99
Copy link
Collaborator

@imrn99 imrn99 commented Oct 28, 2024

  1. remove a useless if / wrong range in the second construction loop
  2. fuse and flatten both construction loops, removing redundant computations at the same time
  3. replace link usages with set_beta usages
  4. set the last assertion to debug only (it can be removed entirely I think).

performance changes for a 512x512 grid (exec time in ms):

Grid type Original new fetch_ Optim 1, 2, 3 Optim 4
Square 157.11 89.83 92.98 24.54
Triangle 246.48 120.16 121.79 35.54

@imrn99 imrn99 changed the title refactor(core): imrove grid building routines refactor(core): improve grid building routines Oct 28, 2024
@codecov-commenter
Copy link

codecov-commenter commented Oct 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.60%. Comparing base (d79671f) to head (fad1ca0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   82.04%   82.60%   +0.56%     
==========================================
  Files          41       41              
  Lines        5681     5865     +184     
==========================================
+ Hits         4661     4845     +184     
  Misses       1020     1020              

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

Copy link
Member

@cedricchevalier19 cedricchevalier19 left a comment

Choose a reason for hiding this comment

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

I was just wondering if splitting the loop into (the interior domain and then the boundary (last row & last column)) can not make the code easier to read (and perhaps more efficient without a conditional in the middle).

Comment on lines 20 to 21
(0..n_square_y)
.flat_map(|y_idx| (0..n_square_x).map(move |x_idx| (y_idx, x_idx)))
Copy link
Member

Choose a reason for hiding this comment

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

Comment on why flatten the iterations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done in 5d61aa9


// and then build faces
assert_eq!(map.fetch_faces().identifiers.len(), n_square_x * n_square_y);
debug_assert_eq!(map.fetch_faces().identifiers.len(), n_square_x * n_square_y);
Copy link
Member

Choose a reason for hiding this comment

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

Leave a comment stating why it can impact the performances.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done in 5d61aa9

@imrn99
Copy link
Collaborator Author

imrn99 commented Oct 28, 2024

I was just wondering if splitting the loop into (the interior domain and then the boundary (last row & last column)) can not make the code easier to read (and perhaps more efficient without a conditional in the middle).

I managed to reorganize the code by splitting like you suggested. I also extracted some common functions which should help with readability

It does not seem to make much of a difference performance-wise (maybe 5% better? but laptop numbers aren't really reliable)

@imrn99 imrn99 merged commit 308afbb into master Oct 28, 2024
13 checks passed
@imrn99 imrn99 deleted the improve-builder branch October 28, 2024 15:08
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