News for hackers. Stuff that matters.
Re:JITs are un-ergonomic by bosswipe on Sunday March 29, 2020 @03:13AM (#22717034)
Verbosity makes the programmer slower not the program.
Re:JITs are un-ergonomic by dgoldstein0 on Sunday March 29, 2020 @04:39AM (#22717338)
It depends. For example, you can verbosely write a loop to copy data from one array to another, or you can use memcpy. The later is typically implemented as hand optimised assembly - it's a pretty small number of operations in x86_64. The former - maybe the compiler optimizes, maybe it doesn't. If it does optimize it, it's definitely more complexity in the compiler and slows it down.

In general having some higher level, well optimized helpers can certainly reduce verbosity and increase speed. That said, some types of verbosity just make the programmer write what the compiler would translate to anyway. Or can end up being unnecessary - e.g. a strongly typed language with no inference certain slows the programmer with no effect on the program (though maybe an effect on the type checker).

Re:JITs are un-ergonomic by im3w1l on Sunday March 29, 2020 @09:27AM (#22718817)
A fast memcpy used to be complicated to implement but these days I heard a simple

    rep movsb
will do the trick. This assumes that the source register points to source, destination register points to destination and counter register is set to number of bytes to copy.
Re:JITs are un-ergonomic by pizlonator on Sunday March 29, 2020 @03:25PM (#22721835)
I wish that was true but my data says it isn't:

- A verbose SIMD copy loop is often faster even on modern Intel CPUs that have the more modern rep implementation.

- A simple byte copy loop will beat both SIMD and rep when you're copying smaller amounts at a time.

Re:JITs are un-ergonomic by raverbashing on Sunday March 29, 2020 @04:12AM (#22717246)
Yes I understand some verbosity is structural and won't change anything, for example

SomeClass x = new SomeClass();

won't make anything slower (ignoring auto for now)

Now, I read Java code and I can't help but wonder how things are harder

For example, setters and getters, what would be a simple memory write becomes a function call. Not complaining when you actually need it.

Reading the examples here (and those are not too bad) https://developer.android.com/reference/java/net/HttpURLConn... it seems you have to actually fight the API to get anything done

Why do you need to cast the return of a url.openConnection() to a HttpURLConnection? (I mean, how many connection types exist?)

Re:JITs are un-ergonomic by pgrulich on Sunday March 29, 2020 @04:56AM (#22717403)
So for getters and setters a Jit can inline the function call and in the end you have a direct memory access. In your example you have to cast because URLConnection could be a HttpURLConnection or JarURLConnection. But again a good Jit would speculate that it is always a HttpURLConnection and deoptimize if not.
Re:JITs are un-ergonomic by imtringued on Sunday March 29, 2020 @09:29AM (#22718843)
The JVM also has full information about the class hierarchy at runtime. If you add a class that overrides a function it will deoptimize that overriden function to a virtual function but otherwise the JVM will just treat it as a static function and inline it if necessary.
Re:JITs are un-ergonomic by vips7L on Sunday March 29, 2020 @12:19PM (#22720182)
In modern Java I don't see why you would directly use an HttpURLConnection. The stdlib provides an easy to use HttpClient.

https://docs.oracle.com/en/java/javase/11/docs/api/java.net....

Re:JITs are un-ergonomic by gnosek on Sunday March 29, 2020 @05:15AM (#22717484)
> I mean, how many connection types exist?

Two? https://developer.android.com/reference/java/net/URLConnecti...