This patch is a proposal to save memory and improve performance in the transform code.
And it is also a step to better solve T70873 (deduplicating code and saving memory).
The core of this solution is in the file transform_data.h.
Basically this API allows to allocate a customized TransData with only the members that will be used for the chosen transform mode.
This patch replaces all references of td->any_member to TD(td, tde, any_member).
td being a block that describes how to read tde and tde a pointer to where the component values are allocated.
Performance is not affected. In fact, the solution of this "dynamic" struct is slightly more efficient than the "static" struct.
Here the results comparing the performance of Translate, Rotate and Scale modes with all TransData members deliberately allocated:
| Translate: | Dynamic Struct: | Static Struct: |
|---|---|---|
| TIME CONVERT | 0.086877 | 0.092606 |
| TIME MODE | 0.043432 | 0.044919 |
| TIME END | 0.060370 | 0.063259 |
| Rotate: | Dynamic Struct: | Static Struct: |
|---|---|---|
| TIME CONVERT | 0.088534 | 0.093524 |
| TIME MODE | 0.057113 | 0.060536 |
| TIME END | 0.061892 | 0.057728 |
| Scale: | Dynamic Struct: | Static Struct: |
|---|---|---|
| TIME CONVERT | 0.083790 | 0.090281 |
| TIME MODE | 0.064508 | 0.065083 |
| TIME END | 0.059783 | 0.062925 |
And here are the results of transforming a mesh but with TransData without the ob, con, ext, hdata, val and ival members:
| Translate: | Dynamic Struct: | Static Struct: |
|---|---|---|
| TIME CONVERT | 0.073605 | 0.093007 |
| TIME MODE | 0.036712 | 0.049270 |
| TIME END | 0.051502 | 0.068967 |
| Rotate: | Dynamic Struct: | Static Struct: |
|---|---|---|
| TIME CONVERT | 0.078153 | 0.093721 |
| TIME MODE | 0.056614 | 0.061064 |
| TIME END | 0.052434 | 0.060353 |
| Scale: | Dynamic Struct: | Static Struct: |
|---|---|---|
| TIME CONVERT | 0.072316 | 0.091699 |
| TIME MODE | 0.058838 | 0.063039 |
| TIME END | 0.051308 | 0.057378 |
It is an improvement in performanse around 20% and still have room for more.
But while it has the advantage of performance and memory usage, there are other points that need to be considered:
- It can complicate the code investigation since we are no longer working with a conventional object and we cannot use the IDE to access the definition of each member or its values.
- It can induce errors since the coder can forget that a component is optional and not add a condition to its existence before.