Repository navigation
Remove platform.architecture() in FITS _array_to_file to improve speed on Mac - #2345
Conversation
|
To profile I put the |
|
Seems fine to cache the architecture -- by definition should be very unlikely to change during the runtime of the application ;) |
|
I just saw that there's a note at https://docs.python.org/2/library/platform.html#platform.architecture that suggests that I'll wait for @embray to comment why he put the extra # Implements a workaround for a bug deep in OSX's stdlib file writing
# functions; on 64-bit OSX it is not possible to correctly write a number
# of bytes greater than 2 ** 32 and divisble by 4096 (or possibly 8192--
# whatever the default blocksize for the filesystem is).
# This issue should have a workaround in Numpy too, but hasn't been
# implemented there yet: https://github.com/astropy/astropy/issues/839
osx_write_limit = (2 ** 32) - 1
if (sys.platform == 'darwin' and platform.architecture()[0] == '64bit' and
arr.nbytes >= osx_write_limit + 1 and arr.nbytes % 4096 == 0): |
|
No, relying on I think the deeper question is why does |
|
Oh, when you mentioned caching though I didn't realize this call was happening in a loop. I'm sort of surprised it gets called so many times because usually that function is just used to write one array in full. But if used with variable-length arrays (as would be the case with a compressed image) then maybe it gets called that many times. So caching the check in that context makes sense. All the more reason to just go ahead and remove the |
… workaround is only needed for 64-bit OSX systems, that comprises the vast majority of OSX systems in use. The workaround does not add significant overhead for 32-bit systems (and is not even likely to be encountered since most 32-bit systems won't be able to handle such large arrays to begin with).
|
Okay, the attached fix should make this much better. Thanks for calling this out! |
|
Changed the title to reflect the proposed fix. |
|
Just to confirm ... the attached fix by @embray does reduce the runtime for this test from 13 seconds to 1 second, to 👍 to merge. |
|
Haha, wow. Sorry about that :D |
|
Looks good - merging! |
Remove platform.architecture() in FITS _array_to_file to improve speed on Mac
Remove platform.architecture() in FITS _array_to_file to improve speed on Mac
In #2317 I noticed that
TestImageFunctions::test_lossless_gzip_compressioninastropy/io/fits/tests/test_image.pyis very slow on Mac (~12 seconds).The problem is https://github.com/astropy/astropy/blob/master/astropy/io/fits/util.py#L600 where you introduced a call to
platform.architecture()in #839.This is called 2002 times by
TestImageFunctions::test_lossless_gzip_compressionand platform.architecture() takes 5.3 milli-seconds on my Mac.@embray I'm not sure what the best fix is here ... probably cache the platform somewhere?