Re: Why CLEventList has fixed size?
Posted by
Wibowit on
Mar 20, 2011; 9:44pm
URL: https://forum.jogamp.org/Why-CLEventList-has-fixed-size-tp2705613p2707338.html
Well, premature optimization is a sign of a bad designer :)
Did you compare the performance?
My test code:
http://pastie.org/1693672Console output (from NetBeans):
run:
Control value: 3854175008845418994
Arrays testing time: 425 ns
Control value: 3854175008845418994
Buffers testing time: 4178 ns
BUILD SUCCESSFUL (total time: 4 seconds)
Million allocations in 4 seconds gives 250k allocations per second on Core2 Duo E8400. I doubt anyone will even get close. If you add a pool of small unused Buffers then the difference will be much smaller. Additionally (or alternatively) you can create a bunch of small sub-Buffers from slicing one preallocated big Buffer.
There are many possibilities to reduce the number of direct (de-) allocations so you can safely implement a dynamically-sized list and when someone will complain about poor Events lists performance then you can add some logic/ strategies that reduces the number of allocations - or he can use the fixed size lists.
There is a second thing I would want you to change. Every method that return an Event expects a CLEventList although it returns only one Event. I suggest creating a class CLEventHolder that will have a field of type CLEvent and will be used to pass the resulting Event to calling routine. Additionally you could add a method addFrom(CLEventHolder) to class CLEventList that will append the Event from that holder to the list.
With the aid of WeakReferences one could even do automatic releasing of Events (and other objects) - ie integrate it with Garbage Collection.
PS: I'm only starting writing OpenCL application, I don't have much experience with it but I insist on flexibility of solutions.