openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.88k stars 3.59k forks source link

Suggestion: Improvement of Java Autoboxing and Unboxing #4560

Closed o0lwj0o closed 5 years ago

o0lwj0o commented 5 years ago

Hi, I have found some usage of “int a = Integer.valueOf(String)” in this project. In fact the return type of “Integer.valueOf()” is “Integer” which is wrapper class. Wrapper class stores in the heap rather than stack. It take more time to loopup. The other potential problem is that Java implement autoboxing and unboxing since JDK 1.5. If run this in low version JDK, it may get trouble. Furthermore, in the above case, it need to cast Integer to int. I recommend use “Integer.parseInt(String)” which return type is int to improve its performance.

PS: This case also applies to “double-Doubel”, “float-Float”, “long-Long” and so on.

Detail websites and lines are listed below

Double.valueOf() | 419 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.pulseaudio/src/main/java/org/openhab/binding/pulseaudio/internal/PulseaudioClient.java   | 181 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/core/TelldusCoreDeviceController.java

Long.valueOf() | 266 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.dlinksmarthome/src/main/java/org/openhab/binding/dlinksmarthome/internal/motionsensor/DLinkMotionSensorCommunication.java   | 815 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.helios/src/main/java/org/openhab/binding/helios/internal/handler/HeliosHandler221.java   | 664 1257 1269 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/handler/TeslaHandler.java   | 52 66 80 94 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/DishwasherChannelSelector.java   | 421 937 1025 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/TeslaChannelSelectorProxy.java   | 55 69 83 97 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/WashingMachineChannelSelector.java   | 29 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/util/UniFiTimestampDeserializer.java   | 53 67 81 95 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/OvenChannelSelector.java   | 84 68 82 94 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/TumbleDryerChannelSelector.java

Integer.valueOf() | 98 109 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.ftpupload/src/main/java/org/openhab/binding/ftpupload/internal/FtpUploadHandlerFactory.java   | 62 67 108 113 137 175 180 205 208 235 240 264 267 294 299 323 326 348 374 378 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.pulseaudio/src/main/java/org/openhab/binding/pulseaudio/internal/cli/Parser.java   | 343 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.yamahareceiver/src/main/java/org/openhab/binding/yamahareceiver/internal/handler/YamahaZoneThingHandler.java   | 328 343 356 359 362 367 368 392 393 394 395 400 402 407 426 435 445 450 464 465 466 467 472 474 486 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/NikoHomeControlCommunication.java   | 648 658 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/internal/handler/SqueezeBoxPlayerHandler.java   | 369 370 385 386 405 422 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.irtrans/src/main/java/org/openhab/binding/irtrans/internal/handler/EthernetBridgeHandler.java   | 271 280 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/live/TelldusLiveBridgeHandler.java   | 48 84 114 137 172 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/OceanicBindingConstants.java   | 359 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/handler/IPBridgeHandler.java   | 129 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.hdanywhere/src/main/java/org/openhab/binding/hdanywhere/internal/handler/Mhub4K431Handler.java   | 102 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.hdanywhere/src/main/java/org/openhab/binding/hdanywhere/internal/handler/MultiroomPlusHandler.java   | 108 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/handler/MiIoVacuumHandler.java   | 37 | https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.onewiregpio/src/main/java/org/openhab/binding/onewiregpio/internal/OneWireGPIOBindingConstants.java   | 138 | https://github.com/openhab/openhab2-addons/blob/master/addons/io/org.openhab.io.openhabcloud/src/main/java/org/openhab/io/openhabcloud/internal/CloudService.java

Best regards

wborn commented 5 years ago

Can you also create a PR for improving this?

If we want to prevent these issues we could also enable some of the Spotbugs performance checks in SAT:

https://spotbugs.readthedocs.io/en/stable/bugDescriptions.html#performance-performance

o0lwj0o commented 5 years ago

@wborn I am glad to submit a PR later.

kaikreuzer commented 5 years ago

@o0lwj0o How much later? Do you still have it on your todo list?

wborn commented 5 years ago

Let's close this issue since there is no PR or reply from @o0lwj0o.