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

minor optimisations #4549

Merged
merged 3 commits into from
Jan 28, 2022
Merged

minor optimisations #4549

merged 3 commits into from
Jan 28, 2022

Conversation

bjlittle
Copy link
Member

@bjlittle bjlittle commented Jan 27, 2022

🚀 Pull Request

Description

This PR introduces an optimisation to iris.cube.Cube.coord_dims, and also a lesser optimisation to merge.

This change contributes, in part, to addressing the use case raised by issue #4538. As a result, I've seen a rough 25% speed-up of the worst case scenario given in #4538 (on my desktop) i.e., loading a 24,000 field PP file (time series) has gone from ~80secs to ~60secs.

Essentially, a cheap win saving can be achieved by not blindly calling iris.cube.Cube.coord within iris.cube.Cube.coord_dims, particularly when the actual cube coordinate that exists within the cube is provided to the coord_dims method.

The philosophy of coord_dims is to avoid coordinate equivalence, as it is a relatively expensive operation, but rather use object identity instead, if possible.


Consult Iris pull request check list

@wjbenfold wjbenfold self-requested a review January 28, 2022 09:18
@bjlittle
Copy link
Member Author

bjlittle commented Jan 28, 2022

The benchmarks have registered a significant increase in performance, which is reassuring... Although they don't specifically target the use case of #4538.

That said, this change seems like a general good win IMHO

@wjbenfold wjbenfold self-assigned this Jan 28, 2022
@bjlittle
Copy link
Member Author

I'll add an appropriate whatsnew entry...

Copy link
Contributor

@wjbenfold wjbenfold left a comment

Choose a reason for hiding this comment

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

Changes to _merge and cube look good to me

@wjbenfold
Copy link
Contributor

FWIW, I can't see an explicit test of the cube.coord_dims function (though there are a lot of tests that use it)

@bjlittle
Copy link
Member Author

I don't believe we need an explicit test for this, it's more than exercised with existing tests.

But that's just my opinion 😉

@bjlittle
Copy link
Member Author

BTW I'm pretty much AWTK today, so don't let a lack of whatsnew entry block this PR @wjbenfold

If you've got capacity, and think it's worthwhile, perhaps add one as a follow on?

@wjbenfold
Copy link
Contributor

Would like to see unit testing of Cube.coord_dims but don't feel it needs to block this given the incidental integration test coverage by other tests. Checked this view with @lbdreyer

Raised #4552

@wjbenfold wjbenfold merged commit 53c93cb into SciTools:main Jan 28, 2022
@@ -1809,7 +1809,8 @@ def key_func(coord):

# Order the coordinates by hints, axis, and definition.
for coord in sorted(coords, key=key_func):
if not cube.coord_dims(coord) and coord.shape == (1,):
dims = tuple(cube.coord_dims(coord))
if not dims and coord.shape == (1,):
Copy link
Member

Choose a reason for hiding this comment

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

FWIW I was looking at this only yesterday, in quite another context
And, I think that the shape didn't really need testing :
if it has no cube-dims, it must be scalar, no?

tkknight added a commit to tkknight/iris that referenced this pull request Mar 16, 2022
* main: (64 commits)
  [pre-commit.ci] pre-commit autoupdate (SciTools#4587)
  fix test (SciTools#4585)
  Loading Benchmarks (SciTools#4477)
  Fix refresh lockfile worrkflow pull request title (SciTools#4579)
  gha: lockfiles labels and auto-pr details (SciTools#4578)
  Bump actions/script from 4 to 5.1.0 (SciTools#4576)
  Bump actions/stale from 4.0.0 to 4.1.0 (SciTools#4575)
  Bump peter-evans/create-pull-request from 3.8.2 to 3.12.1 (SciTools#4577)
  adopt dependabot GHA (SciTools#4568)
  New tool-agnostic ASV environment management (SciTools#4571)
  Updated environment lockfiles (SciTools#4567)
  Update version to 3.3.dev0 (SciTools#4565)
  Reset whats new (SciTools#4563)
  docs: move whatsnew (SciTools#4540)
  Deprecate regrids (SciTools#4548)
  Update latest.rst (SciTools#4556)
  Updated environment lockfiles (SciTools#4555)
  Added whatsnew for SciTools#4551. (SciTools#4553)
  Update SciTools#4505 doctests for SciTools#4528. (SciTools#4554)
  minor optimisations (SciTools#4549)
  ...
@bjlittle bjlittle deleted the optimisations branch June 29, 2022 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants