File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes casting optimization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "casting optimization" Watch "casting optimization" New topic
Author

casting optimization

paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20496
    ∞

Jack,
In your article at http://java.oreilly.com/news/javaperf_0900.html you talk about the great time savings of reducing casts of Object to String. What about casting an int to, say, a char?

permaculture Wood Burning Stoves 2.0 - 4-DVD set
Jack Shirazi
Author
Ranch Hand

Joined: Oct 26, 2000
Posts: 96
Avoiding any cast is a plus. Object type casts are basically a VM version of runnning 'instanceof' on the object. Primitive data type casts are data conversions. Because the primitive type cast consists of the VM mapping a bunch of bits of one size & format to a bunch of bits of another size & format, it is a pretty fast data conversion. But nevertheless, if you can manipulate code to avoid a cast completely, then that is one less operation the code needs to execute. HotSpot tries to eliminate casts wherever it can, even in some cases by speculatively assuming a data type and not bothering with the cast. If the assumption turns out to be wrong, then HotSpot actually has to deoptimize the code to get back to the slower, safer version.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: casting optimization
 
Similar Threads
Array list > for loop or iterator
iterating over unchanging collections
Top Ten JSP Tips
future of java technology
collection.size() vs. array.length