tornavis/source/blender/python/intern
Bogdan Nagirniak 9075ec8269 Python: add foreach_get and foreach_set methods to pyrna_prop_array
This allows fast access to various arrays in the Python API.
Most notably, `image.pixels` can be accessed much more efficiently now.

**Benchmark**

Below are the results of a benchmark that compares different ways to
set/get all pixel values. I do the tests on 2048x2048 rgba images.
The benchmark tests the following dimensions:
- Byte vs. float per color channel
- Python list vs. numpy array containing floats
- `foreach_set` (new) vs. `image.pixels = ...` (old)

```
Pixel amount: 2048 * 2048 = 4.194.304
Byte buffer size:  16.8 mb
Float buffer size: 67.1 mb

Set pixel colors:
    byte  - new - list:    271 ms
    byte  - new - buffer:   29 ms
    byte  - old - list:    350 ms
    byte  - old - buffer: 2900 ms

    float - new - list:    249 ms
    float - new - buffer:    8 ms
    float - old - list:    330 ms
    float - old - buffer: 2880 ms

Get pixel colors:
    byte - list:   128 ms
    byte - buffer:   9 ms
    float - list:  125 ms
    float - buffer:  8 ms
```

**Observations**

The best set and get speed can be achieved with buffers and a float image,
at the cost of higher memory consumption. Furthermore, using buffers when
using `pixels = ...` is incredibly slow, because it is not optimized.
Optimizing this is possible, but might not be trivial (there were multiple
attempts afaik).

Float images are faster due to overhead introduced by the api for byte images.
If I profiled it correctly, a lot of time is spend in the `[0, 1] -> {0, ..., 255}`
conversion. The functions doing that conversion is `unit_float_to_uchar_clamp`.
While I have an idea on how it can be optimized, I do not know if it can be done
without changing its functionality slightly. Performance wise the best solution
would be to not do this conversion at all and accept byte input from the api
user directly, but that seems to be a more involved task as well.

Differential Revision: https://developer.blender.org/D7053

Reviewers: JacquesLucke, mont29
2020-03-13 12:59:36 +01:00
..
CMakeLists.txt Cleanup: move Alembic, AVI, Collada, and USD to `source/blender/io` 2020-03-06 16:19:45 +01:00
bpy.c Cleanup: use PyC_StringEnum to path access functions 2019-10-01 05:19:38 +10:00
bpy.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_app.c Cleanup: use named unsigned types in the Python API 2020-02-20 15:40:05 +11:00
bpy_app.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_app_alembic.c Cleanup: remove redundant 'char *' casts 2019-12-20 10:42:57 +11:00
bpy_app_alembic.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_app_build_options.c Build System: Add OpenXR-SDK dependency and WITH_XR_OPENXR build option 2020-03-04 16:45:07 +01:00
bpy_app_build_options.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_app_ffmpeg.c Cleanup: remove redundant 'char *' casts 2019-12-20 10:42:57 +11:00
bpy_app_ffmpeg.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_app_handlers.c Cleanup: remove redundant 'char *' casts 2019-12-20 10:42:57 +11:00
bpy_app_handlers.h doxygen: add newline after \file 2019-02-18 08:22:12 +11:00
bpy_app_icons.c ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_app_icons.h doxygen: add newline after \file 2019-02-18 08:22:12 +11:00
bpy_app_ocio.c Cleanup: remove redundant 'char *' casts 2019-12-20 10:42:57 +11:00
bpy_app_ocio.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_app_oiio.c Cleanup: remove redundant 'char *' casts 2019-12-20 10:42:57 +11:00
bpy_app_oiio.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_app_opensubdiv.c Cleanup: remove redundant 'char *' casts 2019-12-20 10:42:57 +11:00
bpy_app_opensubdiv.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_app_openvdb.c Cleanup: remove redundant 'char *' casts 2019-12-20 10:42:57 +11:00
bpy_app_openvdb.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_app_sdl.c Cleanup: remove redundant 'char *' casts 2019-12-20 10:42:57 +11:00
bpy_app_sdl.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_app_timers.c ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_app_timers.h doxygen: add newline after \file 2019-02-18 08:22:12 +11:00
bpy_app_translations.c Cleanup: use named unsigned types in the Python API 2020-02-20 15:40:05 +11:00
bpy_app_translations.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_app_usd.c USD: Include USD library version in System Info 2020-01-31 11:29:29 +01:00
bpy_app_usd.h USD: Include USD library version in System Info 2020-01-31 11:29:29 +01:00
bpy_capi_utils.c ClangFormat: format '#if 0' code in source/ 2019-04-17 08:24:14 +02:00
bpy_capi_utils.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_driver.c Cleanup: comments (long lines) in python 2019-04-29 20:01:10 +10:00
bpy_driver.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_gizmo_wrap.c Cleanup: comments (long lines) in python 2019-04-29 20:01:10 +10:00
bpy_gizmo_wrap.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_interface.c Cleanup: use named unsigned types in the Python API 2020-02-20 15:40:05 +11:00
bpy_interface_atexit.c Cleanup: use _ex suffix instead of _ext 2019-08-01 18:39:21 +10:00
bpy_intern_string.c Cleanup: use named unsigned types in the Python API 2020-02-20 15:40:05 +11:00
bpy_intern_string.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_library.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_library_load.c Cleanup/refactor: Rename `BKE_library` files to `BKE_lib`. 2020-02-10 13:00:42 +01:00
bpy_library_write.c ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_msgbus.c Cleanup: Message bus, removed incorrect return type from docstring 2020-03-06 14:29:03 +01:00
bpy_msgbus.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_operator.c Revert "PyAPI: expose OperatorType.modal_keymap" 2019-09-16 16:42:25 +10:00
bpy_operator.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_operator_wrap.c Cleanup: spelling 2019-08-18 04:26:34 +10:00
bpy_operator_wrap.h doxygen: add newline after \file 2019-02-18 08:22:12 +11:00
bpy_path.c ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_path.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_props.c Cleanup: define PY_SSIZE_T_CLEAN for Python 2019-10-16 15:58:32 +11:00
bpy_props.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_rna.c Python: add foreach_get and foreach_set methods to pyrna_prop_array 2020-03-13 12:59:36 +01:00
bpy_rna.h Cleanup: use named unsigned types in the Python API 2020-02-20 15:40:05 +11:00
bpy_rna_anim.c Cleanup: keyframing return arguments 2020-03-06 17:05:18 +11:00
bpy_rna_anim.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_rna_array.c Cleanup: use named unsigned types in the Python API 2020-02-20 15:40:05 +11:00
bpy_rna_callback.c Cleanup: Rename ARegion variables from ar to region 2020-03-06 17:19:23 +01:00
bpy_rna_callback.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_rna_driver.c RNA: Cleanup PointerRNA struct 2019-08-23 09:52:12 +02:00
bpy_rna_driver.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_rna_gizmo.c ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_rna_gizmo.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_rna_id_collection.c Cleanup: rename 'private' to 'embedded' for sub-data IDs. 2020-03-11 12:53:10 +01:00
bpy_rna_id_collection.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_traceback.c Cleanup: use ELEM macro for path slash checks 2020-03-07 01:02:37 +11:00
bpy_traceback.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_utils_previews.c ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
bpy_utils_previews.h doxygen: add newline after \file 2019-02-18 08:22:12 +11:00
bpy_utils_units.c Cleanup: remove redundant 'char *' casts 2019-12-20 10:42:57 +11:00
bpy_utils_units.h ClangFormat: apply to source, most of intern 2019-04-17 06:21:24 +02:00
stubs.c ClangFormat: run with ReflowComments on source/ 2019-05-01 11:13:14 +10:00