Static Finish Access Performance

I have a 10K static file with a word in each line. I need to create an array of String [] with all the words. I have 2 options:

  • I create static words final String [] and hardcode manually with all the words in my code.
  • At startup, upload the file, parse it, and create a static array of String [] words with all the words.

Now, my question is that after all this, adding a word from array 1 (pay attention to the final keyword ) is noticeably faster than a word from array 2 (there is no final keyword, because we load words at run time). Does it theoretically matter? And we are talking here about Android, not about Java. But I am interested in both cases.

+3
source share
4 answers

General Java:

There are no byte codes in the JVM to initialize the array, so the compiler finishes creating separate assignment statements for each element of the array that inflates the code. See here for more details .

, . , , .

Android:

DVM JVM, . , .

, , , . , , , .

+2

, . , 2 String, ...

0

, , . , . ( 100%, Java , # , ).

, 10k. [] . , , final, Java JITTER, , [] .

0

Creating a final array does not make its elements final. This is one of the drawbacks of Java compared to C ++. The only practical effect would be with optimizers and obfuscators. With what you described, I am sure that there will be no noticeable difference.

0
source

Source: https://habr.com/ru/post/1789590/


All Articles