Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 24307 invoked from network); 18 Feb 2003 19:17:30 -0000 Received: from pcp01741013pcs.howard01.md.comcast.net (HELO savarese.org) (68.54.82.236) by daedalus.apache.org with SMTP; 18 Feb 2003 19:17:30 -0000 Received: from gandalf.savarese.org (gandalf.savarese.org [192.168.1.16]) by savarese.org (8.9.3/8.9.3) with ESMTP id OAA30108 for ; Tue, 18 Feb 2003 14:17:37 -0500 Received: from savarese.org (localhost [127.0.0.1]) by gandalf.savarese.org (8.11.6/8.11.6) with ESMTP id h1IJHbN30737 for ; Tue, 18 Feb 2003 14:17:37 -0500 Message-Id: <200302181917.h1IJHbN30737@gandalf.savarese.org> X-Mailer: exmh version 2.2 06/23/2000 with nmh-1.0.4 To: "Jakarta Commons Users List" Subject: Re: StringBuffer pools and why not to use them In-reply-to: Your message of "Tue, 18 Feb 2003 10:19:40 EST." <0C072E7CC947D511AC9600A0CC734120885E2B@XEON400> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 18 Feb 2003 14:17:37 -0500 From: "Daniel F. Savarese" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N In message <0C072E7CC947D511AC9600A0CC734120885E2B@XEON400>, Lester Ward writes : >I was doing some performance tuning recently and thought to try pooling >StringBuffers. I built a pool for them based on StackKeydObjectPool. Bad >idea. Here is why: A number of Java performance rules of thumb seem to have been invalidated by the latest HotSpot releases. I can't give you the exact reference off the top of my head, but the HotSpot team actually recommends that programmers avoid object pools altogether now and to trust the memory allocation and garbage collection system to perform efficiently. Your experiment appears to support this recommendation. I have not taken the time to investigate the situation in detail, but my general impression is that pooling objects simply to avoid the cost of memory allocation may well not be a win in many cases with the HotSpot runtime that accompanied J2SE 1.4. However, pooling objects whose creation or initialization incur additional costs beyond simple memory allocation--such as database connections, threads, and network connections--is still a major win. There is also evidence that pooling simply to avoid the cost of memory allocation provides major benefits in programs that use many threads running on multiple processors. The memory allocation system is serialized (or at least it was; I vaguely recall plans to parallelize it), which creates a major bottleneck in concurrent programs. Pooling sidesteps this problem. The real performance benefits of the changes introduced in the latest versions of the HotSpot runtime (it's not just a JIT) are still poorly understood, so you have to test things out to gauge the efficacy of optimization techniques that used to be no-brainers. daniel