Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Would Java annotation impact runtime performance?

We know that annotation would cause component scan during startup, but would it impact the runtime performance once all configuration loaded?

Btw, we're building a homegrown lightweight restful service framework, to config routing, we got 2 styles:

  • hard coded enums
  • annotation

One of our colleagues has performance concerns about annotation.

like image 235
BigFatSea Avatar asked Apr 01 '14 03:04

BigFatSea


Video Answer


1 Answers

Yes, the annotations add a couple of milliseconds at run-time. Once the program is running, however, there will be no additional overhead. Before you optimise, it is always a good idea to run the program to check if performance speed is even an issue - if it ain't broken, don't fix it.

If the program is running too slowly, I would wager that the bottleneck isn't the annotations. To optimise it you should write some benchmarking code to find where the bottleneck actually is and optimise the slowest part. Your colleague would better off saving time by running everywhere and eating his food raw than optimising his annotations.

like image 159
Anthony Avatar answered Oct 29 '22 00:10

Anthony