-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[java] Deprecate rule AvoidUsingShortType #2296
Description
Affects PMD Version:
6.21.0
Rule:
AvoidUsingShortType
Description:
The premise for AvoidUsingShortType is "any storage gains found through use of the short type may be offset by adverse impacts on performance". I realize the keyword is "may". According to this StackOverflow answer, the performance impact is trivial. Here is the impact.
- Multiply int: 1.530 ns
- Multiply short: 2.105 ns
- Multiply byte: 2.483 ns
Most code does not spin multiplying numbers together. The impact of occasionally multiplying shorts will hardly ever be noticed (i.e. 0.575 ns).
A program would have to multiply 1 billion shorts to have about a 6 ms impact from using short instead of int. However, loading 1 billion shorts from RAM (i.e. ~2 GB) would cost half as much as loading 1 billion ints from RAM (i.e. ~4 GB). Loading an additional ~2 GB will definitely cost more than 6 ms (probably 33 ms or more). Thus, any performance gains from multiplying ints will minuscule compared to loading the ints.
I propose deprecating this rule. Let people use profilers to discover specific places in code where using an int would be better than using a short.