GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Refactor clib to avoid checking GMT version repeatedly and only check once when loading the GMT library by seisman · Pull Request #3254 · GenericMappingTools/pygmt

Conversation

@seisman

@seisman seisman commented May 16, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Description of proposed changes

In the Session.__enter__ method, we check if the GMT library version is equal to or newer than the required version. This special method is called when entering the context manager, i.e., with Session() as lib. So it means we're repeatedly checking the GMT version.

This PR refactors the clib codes to check the GMT version only once when loading the GMT library.

I expect to see some performance improvements but the benchmarks say no. So I believe the performance improvement should be very little.

https://codspeed.io/GenericMappingTools/pygmt/branches/clib/check-version show an average 2% performance improvement.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@seisman seisman added the run/benchmark Trigger the benchmark workflow in PRs label May 16, 2024
@seisman
seisman marked this pull request as draft May 16, 2024 16:34
@seisman
seisman force-pushed the clib/check-version branch 4 times, most recently from d2ef07d to 90ac95d Compare May 21, 2024 05:31
seisman
seisman commented May 21, 2024
View reviewed changes
Comment thread pygmt/clib/session.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@seisman
seisman force-pushed the clib/check-version branch 5 times, most recently from 07b06ac to b42b758 Compare May 29, 2024 05:38
@seisman
seisman force-pushed the clib/check-version branch 2 times, most recently from 833efb4 to 9907af7 Compare July 24, 2024 09:35
@seisman
seisman marked this pull request as ready for review July 24, 2024 09:37
@seisman seisman added this to the 0.13.0 milestone Jul 24, 2024
@seisman seisman added maintenance Boring but important stuff for the core devs needs review This PR has higher priority and needs review. labels Jul 24, 2024
@seisman seisman changed the title clib: Refactor to check the GMT version only once Refactor the clib module to check the GMT version only once when loading the GMT library Jul 24, 2024
@seisman seisman changed the title Refactor the clib module to check the GMT version only once when loading the GMT library Refactor the clib module to avoid checking GMT version repeatedly and only check once when loading the GMT library Jul 24, 2024
@seisman
clib: Refactor to check the GMT version only once
f55d5d4
@seisman
seisman force-pushed the clib/check-version branch from 9907af7 to f55d5d4 Compare July 24, 2024 09:42
@seisman
Merge branch 'main' into clib/check-version
81e12d9
weiji14
weiji14 reviewed Jul 29, 2024
View reviewed changes
Comment thread pygmt/clib/loading.py
func.restype = ctypes.c_float
major, minor, patch = ctypes.c_uint(0), ctypes.c_uint(0), ctypes.c_uint(0)
func(None, major, minor, patch)
return f"{major.value}.{minor.value}.{patch.value}"

@weiji14 weiji14 Jul 29, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thoughts on returning an instance of packaging.version.Version instead of a str?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@seisman seisman Jul 29, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

but __gmt_version__ should be a string.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@weiji14 weiji14 Jul 29, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Mm ok, could also do str(get_gmt_version()), but ok to just return a string itself. Just thought it could simplify some of the test code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
weiji14
weiji14 approved these changes Jul 29, 2024
View reviewed changes

@weiji14 weiji14 left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Just two tiny suggestions. Having the code spread across clib/__init__.py, clib/loading.py and clib/session.py is a little confusing, but seems to make sense after going through it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pygmt/tests/test_clib.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pygmt/tests/test_clib.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@seisman @weiji14
Apply suggestions from code review
00ee9b4
Co-authored-by: Wei Ji <[email protected]>
@seisman seisman changed the title Refactor the clib module to avoid checking GMT version repeatedly and only check once when loading the GMT library Refactor clib to avoid checking GMT version repeatedly and only check once when loading the GMT library Jul 29, 2024
@seisman
seisman merged commit 3a589fa into main Jul 29, 2024
@seisman
seisman deleted the clib/check-version branch July 29, 2024 02:25
@seisman seisman removed the needs review This PR has higher priority and needs review. label Jul 29, 2024
@seisman seisman removed the run/benchmark Trigger the benchmark workflow in PRs label Jul 29, 2024
@weiji14 weiji14 added enhancement Improving an existing feature and removed maintenance Boring but important stuff for the core devs labels Sep 5, 2024
@seisman seisman mentioned this pull request Oct 10, 2024
clib.Session: Add type hints and reformat docstrings (part 1) #3504
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@weiji14 weiji14 weiji14 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

enhancement Improving an existing feature

Projects

None yet

Milestone

0.13.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@seisman @weiji14
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.