> I am aware of the pitfalls of premature optimization, I just got a
> tickle that I am throwing away what could amount to hundreds or
> thousands of objects a minute and it became obvious this is a routine
Thousand of objects a minute? Let's be generous and assume manual
caching, rather than slowing the system down, does actually save a dozen
cycles an allocation. Doing that a thousand times a minute is 12 * 1000
/ 60 = 200 cycles saved a second. On a machine doing, say, 2,000,000,000
cycles a second, that's probably not going to be useful.
> decision other people have dealt with long ago. BTW I am using 1.4 --
> no iterables. Frankly, I cannot afford the time to bring every
> platform up to current and learn a new API every 6 months. Every 2
> years is more my speed, when a new feature will make an important
> impact on what I am doing.
Or Iterable subtypes. Collection for instance. Unfortunately that
interface may be a somewhat wider than you need.
Tom hawtin
Lew - 13 Mar 2007 00:14 GMT
christopher@dailycrossword.com wrote:
>> I am aware of the pitfalls of premature optimization, I just got a
>> tickle that I am throwing away what could amount to hundreds or
>> thousands of objects a minute and it became obvious this is a routine
> Thousand of objects a minute? Let's be generous and assume manual
> caching, rather than slowing the system down, does actually save a dozen
> cycles an allocation. Doing that a thousand times a minute is 12 * 1000
> / 60 = 200 cycles saved a second. On a machine doing, say, 2,000,000,000
> cycles a second, that's probably not going to be useful.
Plus the Java GC is extremely efficient at small, short-lived objects. There
is an overhead of about 12-20 machine cycles for object creation, according to
estimates I've read, and none whatsoever for young generation object
destruction. Java's memory allocation dynamics tend to favor creating small
throwaway objects over hanging on to them.
The overhead of tenured GC for long-lived objects may overwhelm the small
savings in object creation. It very likely will increase programming
difficulty as you try to manage manually what Java can manage quite well
automatically.
This does not apply to objects that maintain external resources, such as
database connections. There the memory management overhead is insignificant
compared to the resource overhead.
christopher@dailycrossword.com wrote:
>> BTW I am using 1.4 -- no iterables.
>> Frankly, I cannot afford the time to bring every
>> platform up to current and learn a new API every 6 months.
>> Every 2 years is more my speed,
Java 5 has been out for about two and a half years, so "6 months" is really
not an issue in this case. If "every 2 years is more [your] speed" then it's
time to take a look.
Java 6 is the current version.
-- Lew
christopher@dailycrossword.com - 13 Mar 2007 05:48 GMT
hehe I know I am overdue on my 2 year cycle. We have a new server
cluster coming online in a couple months and I am going to mirror that
setup to my development server. My least favorite surprise is finding
out that my 2 year old FreeBSD install is not current enough to run
the Java 1.6 port. Sigh.
Thanks for the info on GC being efficient with small, short lived
objects. I always assumed the intent behind iterators and their kin
was for them to be throw-aways, but assumptions like that can bite
hard.
Cheers!
> christop...@dailycrossword.com wrote:
> >> I am aware of the pitfalls of premature optimization, I just got a
[quoted text clipped - 34 lines]
>
> -- Lew