File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes disabled assertion & performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "disabled assertion & performance" Watch "disabled assertion & performance" New topic
Author

disabled assertion & performance

Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
This is an out-of-scope post. The information in this post is probably not needed for the exam.
The purpose of this post is to point out a contradiction *within* the Programming With Assertions document
http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html
One place says there is no performance penalty for disabled assertions. The other place says there may be a performance penalty.
In the Introduction,
Disabling assertions eliminates their performance penalty entirely. Once disabled, they are essentially equivalent to empty statements in semantics and performance.

In section Putting Assertions Into Your Code, subsection Advanced Uses, subsection Removing all Trace of Assertions from Class Files,
While this makes it impossible to enable assertions in the field, it also reduces class file size, possibly leading to improved class loading performance. In the absence of a high quality JIT, it could lead to decreased footprint and improved runtime performance.

This section gives advice on how to remove assertions from class files. This is their way to ensure there is no performance penalty.
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

You're right Marlene, this is a bit out of scope. I'm moving this to the JavaInGeneral(Advanced) forum where its a better fit.
Please continue the discussion there.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
"In the abscence of a high quality JIT" is the key here. I don't know of any compiler that has a problem with assertions and in fact I find it hard to imagine that there is a 1.4 compiler that would have a problem with assertions and performance. I would say that this is an example of paranoia on the part of the person who wrote the document.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Another point is that there are several types of "performance" that might be discussed. The most common to consider is after a class has been loaded and you want to run a method, how long does it take? (Especially if you do so repeatedly?) This is the sort of thing where a good JIT will pretty much eliminate any effect of assertions (when they're disabled that is), and it's most likely what was being talked about in the first quote. However the second quote mentions a number of other considerations such as class file size and class loading time. If your .java file contains a lot of assertions, well, the .class file will have to contain the extra byte codes to describe what each one does, and at runtime when the class is loaded it's going to take some extra time to read those extra bytes and decide what to do about them (which is most likely, just skip them). This is a one-time effect when a class is loaded, so if you write a test case that runs a method 1000000 times to see how long it takes, you wouldn't see it - the class only loads once. But it's remotely possible that you are writing some application where this makes a difference, e.g. for an applet where the time it takes to download the .jar file is something you want to really minimize, or for some program that you want to start as quickly as possible after the JVM is started. I believe the total effect in this case will still be pretty small in most cases unless you really write a lot of assertions - but yes there is some effect in some cases.
So - if we were to take the second quote and eliminate the parts about "in the absence of a high quality JIT" and "decreased runtime performance" then the two quotes would really be completely unrelated, IMO. The second quote is mostly about the class file size and class loading time; the first is about performance after the class is loaded. So there's no contradiction. When we re-insert those clauses, well, as Tom says "in the absence of a high quality JIT" is key. If you're using JDK 1.4, hey, you've got an excellent JIT, so don't worry. The person who wrote that line was just being paranoid that maybe you might want to run on an ACME CrapVM™ or something, and he can't guarantee that all JVMs will handle assertions so well.
Also, Marlene - I'm another person who likes to obsess over this level of detail, and I like to think that's a good thing. But I want to add that these other moderators are right when they keep moving your questions out of Programmer Cert and into other forums like JiG Advanced or Performance. The vast majority of people in Programmer Cert really, really do not need to see this level of detail, and we don't need to scare them with it. (Though prefacing your post with "this is an out-of-scope post" is helpful in this case, thanks.) Plus those of us who actually do like this level of detail generally aren't hanging out in Programmer Cert much - Performance and JiG Advanced are much better for reaching your desired target audience.


"I'm not back." - Bill Harding, Twister
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Thank you Thomas. Until I got to the very end of your reply, I thought you were going to say: this is an example of paranoia on the part of the person who wrote the post!
Thank you Jim for your point view. Thank you for your time.
Dear members #970 and #290 (gulp!) I will give even more thought to whether or not I should post some topic.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by Marlene Miller:
Dear members #970 and #290 (gulp!) I will give even more thought to whether or not I should post some topic.

Don't worry about posting. Just worry about where you post it. Keep questions about the cert in the cert forums but stuff like this should be somewhere else.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: disabled assertion & performance