It’s time for the first episode of UVPackmaster2 new feature series
UVPACKMASTER 2.0 NEW FEATURES, EPISODE 1: Refactor of the CPU packing algorithm
In UVPackmaster2 we introduced general improvements of the CPU packing algorithm which resulted of approx. 20% better per-core performance. But the biggest performance boost in the new version comes from the changes made in multi-threading handling.
The most straightforward approch to multithreading in UV packing is to use ‘single orientation’-‘single thread’ scheme. In such implementation a single thread is searching for a place for a single orientation of a UV island. This scheme is used by almost every UV packer out there, it was also used in UVPackmaster1.
Such approach is easy to implement, but it has a major drawback. Imagine you have a 16-core CPU in your system. In order to use 100% processing power of your CPU you have to consider at least 16 orientations for every island (i.e. set ‘Rotation Step’ to a very small value). But for most UV maps processing so many orientations is not necessary - it simply won’t improve the final packing result. Quite often rotation step set to 90 (i.e. 4 orientations for every island) is enough to get an optimal packing. So you decide to decrease the number of orientations from 16 to 4. But with the simple multi-threading approach you won’t get any performance benefits from that - your 16-core CPU will only use 4 cores during packing and the overall packing time will be the same.
That is the reason why we decided to redesign the multi-threading algorithm in UVPackmaster2. It is much more sophisticated now - it uses all cores in your system no matter what packing parameters are.
Off-course a bunch of numbers is worth a thousand words so we did a simple benchmark:
CPU: Ryzen 2700, 8 cores
Rotation step: 90 (4 orientations per island)
UVPackmaster 1.91: 86 ms.
UVPackmaster 2.0: 33 ms.
As you can see UVPackmaster2 is more than 2 times faster than UVPackmaster1 - and it is expected as UVPackmaster1 used 4-cores only out of 8 cores available
But do not assume that you must have a multi-core CPU in order to benefit from multi-threading redesign. Note that for UV maps containing a huge number of small islands you can even disable rotation completely and still you will get an optimal solution. So even if your CPU has 2 cores only UVPackmaster2 will pack such UV map approx. 2 times faster than UVPackmaster1. See the example:
CPU: i5-2450M, 2 cores
Rotation step disabled
UVPackmaster 1.91: 562 ms.
UVPackmaster 2.0: 209 ms.
As you can see results are as expected.
Now the funny thing: if you look at the very first post in this thread, the post in which I announced the very early release of UVPackmaster1, you will find there exactly the same UV map as the one above. In the post I wrote that it took about 21 seconds for UVPackmaster1 to pack this UV map. UVPackmaster2 only needs 209 ms. to pack it. Both tests done on the same laptop, the same processor: i5-2450M. It shows how much this software evolved during last half of the year