java - Can using non primitive Integer/ Long datatypes too frequently in the application, hurt the performance? -


i using long/integer data types in application, build generic datatypes. fear using these wrapper objects instead of primitive data types may harmful performance since each time needs create objects expensive operation. seems have no other choice(when have use primtives generics) rather using them.
however, still great if can suggest if there make better. or way if avoid ??

also may downsides of ?

suggestions welcomed!

repeat after me. "creating object in java not expensive operation".

you prematurely optimizing application. better approach implement in natural way using integer , long, profile determine bottlenecks are. if profiler tells use of integer , long performance issue, then @ ways cure this.


if determine integer , long issue, here things do:

  • look class library implements "collections" of primitive types; e.g. trove. beware apis of such collection types won't compatible java.util.collection , descendants.

  • use integer.valueof(int) , long.valueof(long) rather new integer(int) , new long(long). valueof methods use cache of used objects reduce number of object creations.


@rex kerr's comment horrible advice. (i think) saying op should optimize application reduce use of integer , long before knows performance concern. disagree.

  • at point (when asked question), op didn't know application needed optimization. if application runs "fast enough" without optimization, developer time spent optimizing better spent on else.

  • at point, op doesn't know where performance bottlenecks are. if not in handling of these values, optimizing aspect waste of time. note speaking bad idea rely solely on intuition tell bottlenecks or be.

  • @rex kerr posits lot of work modify/restructure code fix performance issues due over-use of integer , long. that's not true. decent ide makes easy make sort of change in small medium size application.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -