Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> that generally require more runtime logic and safety checks.

These safety checks and runtime logic are a constant factor in the performance of a given java application.

Further, they are mostly miniscule compared to other things you are paying for by using java. The class check requires loading the object from main memory/cpu cache but the actual check is a single cycle cmp check. Considering the fact that that object will then be immediately used by the following code (hence warm in cache) the price really isn't comparable to the already existing overhead of reaching down into ram to fetch it.

I won't say there aren't algorithms that will suffer, particularly if you are doing really heavy data crunching that extra check can be somewhat murder. However, in the very grand scheme of things, it's nothing compared to all the memory loading that goes on in a typical java application.

That is to say, the extra class cast on an `ArrayList<Point>` is nothing compared to the cost of the memory lookups when you do

    int sum = 0;
    for (var point : points) {
      sum += point.x + point.y + point.z
    }


> The class check requires loading the object from main memory/cpu cache but the actual check is a single cycle cmp check.

Only a guard or, possibly, a final class type-check (at least it's the case for sealed classes or exact type comparisons in .NET). For anything else this will be more involved due to inheritance.

Obviously for any length above ~3 this won't dominate but JVM type system defaults don't make all this any easier.


I'm not an expert but I think that the compiler requires the exact class on insertion so at use it's just a check.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: