charmplusplus / charm4py

Parallel Programming with Python and Charm++
https://charm4py.readthedocs.io
Apache License 2.0
290 stars 21 forks source link

Optimize metadata packing for Numpy arrays of 'builtin' types #209

Closed ZwFink closed 3 years ago

ZwFink commented 3 years ago

When sending messages that contain numpy arrays of built-in types, it is faster to access array.dtype.char than it is to access array.dtype.name. More information about datatypes in numpy can be found here. This patch adds a check for whether a numpy array contains a built-in type, and if so uses the faster method to obtain the type information. This patch decreases message latency almost 12us (from 35.9us to 24.1us) in a microbenchmark.

This method of accessing the data type is faster because array.dtype.name executes additional Python code as it has to access arbitrary Python strings (in the case where custom types are created/used).