[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fri, 22 Mar 2002 13:32:45 +1000
Rhys Weatherley wrote:
> The first time you call the function, and while it is
> being converted to CVM bytecode, it will hash the
> literal and find the object. This object reference is
> then embedded into the code. Every subsequent
> call to the method will use the object directly,
> with no extra overhead.
My mistake - it does hash the object each time, but it
will not create a new object unless the string literal
has never been seen before. I better fix this I suppose.
Anyway, it doesn't change my point - don't try to
second-guess the engine. It's easier to optimise
cases like this in the engine, than in the pnetlib code.
Using a "static" field forces the system to always do
a lookup on the field. Static fields are quite expensive
to access. Once I optimise string literals some more,
it will be a simple "load pointer onto stack" operation,
which is much more efficient that a static field access.