D
D
Daniel2021-02-26 00:28:33
JVM
Daniel, 2021-02-26 00:28:33

Why does a bytecode virtual machine run nearly as fast as a machine code program?

How many did not come across performance measurements, then almost always somewhere at the level of + -20% of the difference.
Although you intuitively expect a difference in speed by 2+ times, that is, translating 1 instruction bytes of code into machine code by about 2+ (the interpretation of the instruction itself + the execution of this interpretation) times should increase the duration of the execution of this instruction.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rPman, 2021-02-26
@daniil14056

There is such a thing as jit compilation, when your logic is assembled into native binary code right on the run, even virtual machines use it, it allows short blocks of code to be optimized up to 100% performance, and compilation overhead is in a neighboring thread.
For example , they say that llvm ExecutionEngine JIT can work even faster than a binary compiled into native code (probably features of optimizations that are easier to do in jit)

A
Armenian Radio, 2021-02-26
@gbg

Because modern java and js are processed by the jit compiler - the bytecode is distilled into machine code in large optimized pieces.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question