Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Program speed, and performance.

 
Preben
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I use very long variable identifiers. Will this in any
way "slow" down my programs?
I.E.:
String aVeryVeryVeryVeryLongIdentifier =new String("very long");
Has the access modifier any impact on my programs "speed" and
performance?
-Newbie Programmer
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is really a question more suited to the performance forum.
 
paul wheaton
Trailboss
Pie
Posts: 21473
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the time comes to production, a lot of folks run their code through an obfuscator making this question moot.
I suppose it is possible that the name size can make a difference. But it would be up to the JVM that is running it.
 
Preben
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
I also think this is an excellent site!
 
Jack Shirazi
Author
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Longer class & method names should have only one performance impact, which is the size they have on the .class files. The JVM should not run any slower except for the minimal extra time it takes to load a large .class file (possibly including network downloads).
Variable names are different in that variable names are not retained directly in the bytecodes. Instead all variables are compiled to JVM addresses, and the length of the variable name makes no difference at all. However, the compiler is allowed to retain the variable names in the .class file in a separate variable name table, so that debuggers (and decompilers) can use the original names. By default most compilers do retain this table. Retaining the table has the same effect as noted for class/method names, i.e. a larger .class file. You can normally eliminate the variable name table using one of the compiler options, e.g. -O or -g:none (the option varies with the compiler), or you can use an optimizing recompiler that can strip out the variable name table after compilation (see the resources section at my site for a list of some tools that do this).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic