Uh oh!
There was an error while loading. Please reload this page.
Refactor clib to avoid checking GMT version repeatedly and only check once when loading the GMT library - #3254
Conversation
d2ef07d to
90ac95dCompareUh oh!
There was an error while loading. Please reload this page.
07b06ac to
b42b758Compare833efb4 to
9907af7Compare| 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.
Thoughts on returning an instance of packaging.version.Version instead of a str?
There was a problem hiding this comment.
but __gmt_version__ should be a string.
There was a problem hiding this comment.
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.
weiji14
left a comment
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
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.