[Bf-committers] performance variation of BKE_add_object function

Joshua Leung aligorith at gmail.com
Sat Oct 6 02:22:43 CEST 2012


Interesting results, especially those jumps after 1000 and 10000.
First time I've seen this plotted out.

There seem to be two sources of slowness (without actually profiling
to confirm):
1) BKE_libblock_alloc() will sort the objects so that the newly added
object is now in alphabetical order relative to the other objects in
the db. (Actually, it is new_id() -> id_sort_by_name() which does
this, which does an insertion sort O(n))

2) BKE_scene_base_deselect_all() needs to go over all items in scene -
O(m). If all your objects are in the same scene, then m=n.

Now, especially with regards to point 1, this applies to every
datablock in Blender. This means, it really isn't that nice to go
around heaps and heaps of these, especially not in any time critical
loops. Furthermore, creating full "Blender Objects" for quick
throwaway helpers during rendering (I'm only guessing here) seems
quite wasteful, as they're not exactly that lightweight and will hang
around for the rest of the session. Unless there are some capabilities
provided by Blender Objects (i.e. modifiers, constraints, derivedmesh,
etc.) that you really need, perhaps it might be worth considering
checking out a more lightweight approach akin to DupliObjects or so.


On Sat, Oct 6, 2012 at 11:07 AM, Tamito KAJIYAMA
<rd6t-kjym at asahi-net.or.jp> wrote:
> Hi,
> BKE_add_object function displays an appreciable performance decrease as the number
> of objects increases.  The following plot shows the elapsed time per call of the function
> over 11692 objects successively generated (r50956, Windows Vista 64 bit, VS 2008 64 bit).
> http://freestyleintegration.files.wordpress.com/2012/10/add_object_perf.png
> The average time per call is 7.565e-3 seconds, but the time tends to increase over time,
> with some sudden decreases (e.g., at the calls around the 1000th and 10000th objects).
> This performance variation effect is quite visible in the Freestyle branch, where a large
> number of temporary objects are automatically generated for stroke rendering.
> Any thoughts and suggestions concerning this issue are much appreciated.
> Regards,
> --
> KAJIYAMA, Tamito <rd6t-kjym at asahi-net.or.jp>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers

More information about the Bf-committers mailing list