Re: [Vala] reference management.



On Tue, 2007-03-20 at 18:32 +0100, Jürg Billeter wrote:
On Die, 2007-03-20 at 07:18 +0100, Mathias Hasselmann wrote:
Currently all member variables are strongly referenced by default. To
make them weak add exactly this keyword. For local variables currently
some heuristics exist. Weak still is preferred, but there are some
thoughts to use always use strong references for local variables.
Problem with strong references on local variables: Whilst strong
references are quite cheap to maintain for GObject derived classes,
they can be extremely expensive for things like boxed types or GList.

I've removed the heuristic from Vala SVN; local variables default to
strong references now. The compiler will warn if it has to copy
structures without support for reference counting as that might cause
side-effects and might also be expensive for some types. You can still
explictly specify local variables to be weak, so that you can optimize
critical code parts if necessary.


I would recommend sending patches to glib for ref counting for all the
glib data structures (as GHashTable has it Im sure they will accept it
for all the rest if its done in the same way)


We intend to add a full garbage collector to Vala which can be used as
alternative to reference counting as far as possible with GObject. This
might improve performance without manually marking weak references.

Will the GC be compatible with platform stuff though?

Also the GC will add runtime requirements and typically double memory
usage. However its still nice to have as an option...

I would personally use GString (with ref counting patch to glib) as the
basic string type in vala as that this can be managed efficiently
without copying strings via default strong refs. Its also a lot faster
for string concatenation as it allocates extra memory for potential
string growth in chunks (using gslice I believe)

For C interfacing, a cString type should be used with the compiler
automatically converting  from GString to cString just like Delphi does
with its strings.

Also if g_thread_init has not been called it might be a good idea to use
non-threadsafe ref counting which should be a lot faster - hopefully
glib will accept a path for that too!

Im pretty sure the above should eliminate any performance penalties so
hopefully Vala can be treated as a serious language. 

jamie.






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]