> and this is not by mistake

cool

> is there any performance hit, even slightest, when doing things like that in Dart?

I think the answer is, a very very slight performance hit. Nothing that trumps having additional clarity in the code.

We have two runtimes, dart2js and the Dart VM. Dart2js does do a lot of compiler optimizations but my guess is that it does not do this one. It would need to in-line the code for initAnalytics() into the site's which call it. Easy enough to check though, by looking at the generated javascript.

The Dart VM may do this optimization, but would only do it on it's 2nd pass compile. It uses a two stage compiler process, like V8's crankshaft. The first compile generates machine code, including code which instruments the method. At some trigger, the runtime will re-compile the method with an optimizing compiler using data gathered from the instrumentation.

Last I checked, the trigger to re-compile a method was pretty simple. It did it after 4000 invocations. This logic may very well have gotten more sophisticated, but generally, the person calling initAnalytics() would need to be called a lot to trigger an optimized compile.