Home » Android » java – Do comments affect compile time?

java – Do comments affect compile time?

Posted by: admin June 15, 2020 Leave a comment


I’m an Android developer and the following question came to my mind: When I put a big comment in order to compiling process, is that while we put our useful comment in code , can compiler take some time at comment portion?

If no, then is it not get any effect since how long our comment?

How to&Answers:

can compiler take some time at comment portion?

Apart from the IO overhead of traversing the bytes corresponding to the comment (which should be negligible as long as it’s not a several megabyte long comment), it will make no difference what so ever. Most compilers don’t even include the comments in the AST, which means that the comments are completely gone after parsing.

Never decide whether or not to include a comment based on compilation time. Base your decision solely on whether it makes the code more readable or not.

Further reading:


Yes, each comment that you write will make the compilation slower, because the compiler has to read more text. But: reading comments is very easy for a compiler, and it is quickly done, so you should not worry about it.

You can try it out yourself. Make a program that generates some simple source code with lots of comments in it.

int i = 0;
i++; /* This is a comment, and maybe a very long one. */

Now you can experiment with making this (generated) comment very long, possibly even megabytes. Then measure the difference when compiling the code with small and large comments, and you will see that the speed is still acceptable.


It takes time to read and parse these comment block but this time is so short you won’t notice and anyways not an excuse not to put (extended and useful) comments in your programs 🙂