2 comments

  • zahlman32 minutes ago
    &gt; the compiler had enough static information to emit a single arraylength bytecode instruction.<p>I&#x27;m skeptical.<p>If it can <i>prove</i> that the input actually matches the hint, then <i>why does it need the hint</i>?<p>If it can&#x27;t, what happens at runtime if the input is something else?<p>&gt; We replaced a complex chain of method calls with one CPU instruction.<p>JVM bytecodes and CPU instructions really shouldn&#x27;t be conflated like that, although I assume this was just being a bit casual with the prose.
    • mkmccjr9 minutes ago
      Thank you for this! On the second point, you are absolutely correct; that was sloppy writing on my part. I will correct that in the post.<p>I&#x27;m not certain I understand your first point. When I add the type hint, it&#x27;s me asserting the type, not the compiler proving anything. If the value at runtime isn&#x27;t actually a byte array, I would expect a ClassCastException.<p>But I am new to Clojure, and I may well be mistaken about what the compiler is doing.
  • EdNutting5 hours ago
    Wild speculation: Could the extra speedup be due to some kind of JIT hotpath optimisation that the previous reflective non-inlinable call prevented, and which the new use of the single `arrayLength` bytecode enabled? E.g. in production maybe you&#x27;re seeing the hotpath hit a JIT threshold for more aggressive inlinng of the parent function, or loop unrolling, or similar, which might not be triggered in your test environment (and which is impossible when inlining is prevented)?
    • mkmccjr3 hours ago
      Author of the blog post here. That explanation sounds very plausible to me!<p>If the whole enclosing function became inlinable after the reflective call path disappeared, that could explain why the end-to-end speedup under load was even larger than the isolated microbench.<p>I admit that I don&#x27;t understand the JIT optimization deeply enough to say that confidently... as I mentioned in the blog post, I was quite flummoxed by the results. I’d genuinely love to learn more.