diff options
author | Jacques Lucke <jacques@blender.org> | 2022-05-31 21:41:01 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-05-31 21:41:01 +0300 |
commit | 5c80bcf8c2fbd1e3c71ef5169f59e0b95c4db153 (patch) | |
tree | b356acfe3114e062384822fcb7ac93028a267250 /source/blender/functions/FN_multi_function_signature.hh | |
parent | 484ea573af376a483ae7ecd0c1cba95ac5b122c7 (diff) |
Functions: speedup preparing multi-function parameters
My benchmark which spend most time preparing function parameters
takes `250 ms` now, from `510 ms` before. This is mainly achieved by
doing less unnecessary work and by giving the compiler more inlined
code to optimize.
* Reserve correct vector sizes and use unchecked `append` function.
* Construct `GVArray` parameters directly in the vector, instead of
moving/copying them in the vector afterwards.
* Inline some constructors, because that allows the compiler understand
what is happening, resulting in less code.
This probably has negilible impact on the user experience currently,
because there are other bottlenecks.
Differential Revision: https://developer.blender.org/D15009
Diffstat (limited to 'source/blender/functions/FN_multi_function_signature.hh')
-rw-r--r-- | source/blender/functions/FN_multi_function_signature.hh | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/source/blender/functions/FN_multi_function_signature.hh b/source/blender/functions/FN_multi_function_signature.hh index 62c491609a4..6181555dbd1 100644 --- a/source/blender/functions/FN_multi_function_signature.hh +++ b/source/blender/functions/FN_multi_function_signature.hh @@ -29,6 +29,15 @@ struct MFSignature { Vector<int> param_data_indices; bool depends_on_context = false; + /** + * Number of elements of each of these types that has to be passed into the multi-function as an + * input or output. + */ + int span_num = 0; + int virtual_array_num = 0; + int virtual_vector_array_num = 0; + int vector_array_num = 0; + int data_index(int param_index) const { return param_data_indices[param_index]; @@ -38,10 +47,6 @@ struct MFSignature { class MFSignatureBuilder { private: MFSignature signature_; - int span_count_ = 0; - int virtual_array_count_ = 0; - int virtual_vector_array_count_ = 0; - int vector_array_count_ = 0; public: MFSignatureBuilder(const char *function_name) @@ -79,10 +84,10 @@ class MFSignatureBuilder { switch (data_type.category()) { case MFDataType::Single: - signature_.param_data_indices.append(virtual_array_count_++); + signature_.param_data_indices.append(signature_.virtual_array_num++); break; case MFDataType::Vector: - signature_.param_data_indices.append(virtual_vector_array_count_++); + signature_.param_data_indices.append(signature_.virtual_vector_array_num++); break; } } @@ -112,10 +117,10 @@ class MFSignatureBuilder { switch (data_type.category()) { case MFDataType::Single: - signature_.param_data_indices.append(span_count_++); + signature_.param_data_indices.append(signature_.span_num++); break; case MFDataType::Vector: - signature_.param_data_indices.append(vector_array_count_++); + signature_.param_data_indices.append(signature_.vector_array_num++); break; } } @@ -145,10 +150,10 @@ class MFSignatureBuilder { switch (data_type.category()) { case MFDataType::Single: - signature_.param_data_indices.append(span_count_++); + signature_.param_data_indices.append(signature_.span_num++); break; case MFDataType::Vector: - signature_.param_data_indices.append(vector_array_count_++); + signature_.param_data_indices.append(signature_.vector_array_num++); break; } } |