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
commented
May 16, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.
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
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
|
|
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}"
|
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
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.
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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
Reviewers
weiji14
weiji14 approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|