Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 324331 - redundant Strings created from Version.toString
Summary: redundant Strings created from Version.toString
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Framework (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7 M3   Edit
Assignee: equinox.framework-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-02 12:59 EDT by Mark Stoodley CLA
Modified: 2010-10-28 17:01 EDT (History)
3 users (show)

See Also:


Attachments
Modified version of Version.java (10.52 KB, text/java)
2010-09-02 13:01 EDT, Mark Stoodley CLA
no flags Details
Snapshot of call tree above Version.toString (67.83 KB, image/jpeg)
2010-09-02 14:11 EDT, Mark Stoodley CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Stoodley CLA 2010-09-02 12:59:55 EDT
Build Identifier: R35x_v20090827

org/osgi/framework/Version.toString() builds a String object on every call from elements in the Version object that are private and final.  By caching the String object created the first time (and avoiding creating potentially several StringBuffers and character arrays), the size of the live heap can be reduced which lowers pressure on the garbage collector (at least when Version.toString() is called multiple times on the same Version object).  In a recent Geronimo server version, start-up was significantly (>10%) improved with a simple change to the Version class.

Reproducible: Always
Comment 1 Mark Stoodley CLA 2010-09-02 13:01:45 EDT
Created attachment 178066 [details]
Modified version of Version.java

I've added a new private String field versionString and modified the code inside the toString() method to cache the String object built on the first invocation.
Comment 2 Thomas Watson CLA 2010-09-02 13:20:04 EDT
I am wondering why Version.toString() is getting called over and over so much.  Is that coming from framework code or some other code in a bundle which is calling Version.toString so much?
Comment 3 BJ Hargrave CLA 2010-09-02 13:25:24 EDT
It does seem strange to call toString so much. It is possible this is use in creating descriptive strings from other object which aggregate a Version object. That is, the object's toString method calls Version.toString.

I don't have an issue with updating Version for 4.3 to cache the resulting string.
Comment 4 Mark Stoodley CLA 2010-09-02 14:11:12 EDT
Created attachment 178079 [details]
Snapshot of call tree above Version.toString

Here's a snapshot of a call tree above the calls to Version.toString (sorry, much of class name has been stripped off these names by the tool, but hopefully still gives an idea of what's going on "upstairs").
Comment 5 BJ Hargrave CLA 2010-09-02 15:20:24 EDT
Looks like the framework is at fault here.

I see 24 places in the org.eclipse.osgi project where Version.toString is called. This does not include where Object.toString is called on a Version object.
Comment 6 BJ Hargrave CLA 2010-09-02 20:10:21 EDT
I updated the Version class in the OSGi companion code to cache the toString result. This will soon make its way into 3.7.
Comment 7 Thomas Watson CLA 2010-10-28 17:01:45 EDT
The version class has been updated from OSGi for M3.  The result of Version.toString is now cached.