티스토리 뷰

CS

AOT vs JIT

고우어해드 2020. 1. 31. 14:26

AOT와 JIT는 컴파일 방식이 다르다

JIT 컴파일 (Just-in-time 즉시)

JIT 컴파일(just-in-time compilation) 또는 동적 번역(dynamic translation)은 프로그램을 실제 실행하는 시점에 기계어로 번역하는 컴파일 기법이다. 이 기법은 프로그램의 실행 속도를 빠르게 하기 위해 사용된다.

전통적인 입장에서 컴퓨터 프로그램을 만드는 방법은 두 가지가 있는데, 인터프리트 방식과 정적 컴파일 방식으로 나눌 수 있다. 이 중 인터프리트 방식은 실행 중 프로그래밍 언어를 읽어가면서 해당 기능에 대응하는 기계어 코드를 실행하며, 반면 정적 컴파일은 실행하기 전에 프로그램 코드를 기계어로 번역한다.

JIT 컴파일러는 두 가지의 방식을 혼합한 방식으로 생각할 수 있는데, 실행 시점에서 인터프리트 방식으로 기계어 코드를 생성하면서 그 코드를 캐싱하여, 같은 함수가 여러 번 불릴 때 매번 기계어 코드를 생성하는 것을 방지한다.

최근의 자바 가상 머신과 .NET, V8(node.js)에서는 JIT 컴파일을 지원한다. 즉, 자바 컴파일러가 자바 프로그램 코드 바이트코드로 변환한 다음, 실제 바이트코드를 실행하는 시점에서 자바 가상 머신이 바이트코드를 JIT 컴파일을 통해 기계어로 변환한다.  - 위키백과 중

 

 

인터프리터와 컴파일 방식을 섞은 것이다. 속도와 편한 디버깅 능력을 갖춤

 

JIT를 쓰는 것들은 JVM(JDK 8부터) , V8 엔진 등이 있다.

 

 

AOT 컴파일

AOT 컴파일(ahead-of-time compile)은 목표 시스템의 기계어와 무관하게 중간 언어 형태로 배포된 후 목표 시스템에서 인터프리터 JIT 컴파일 등 기계어 번역을 통해 실행되는 중간 언어를 미리 목표 시스템에 맞는 기계어로 번역하는 방식을 지칭한다. 이런 중간 언어로는 자바 바이트코드, 공통 중간 언어(Common Intermediate Language), IBM System/38 혹은 IBM System i의 기술 독립적 머신 인터페이스(Technology Independent Machine Interface)가 있으며 학계에서도 마이클 프란즈(Michael Franz)[1]가 제안해 오베론 시스템의 일부 구현에서 사용된 슬림 바이너리(Slim Binaries)와 같은 제안이 있었다.

일반적으로 중간 언어를 사용하는 시스템은 실행 시간에 JIT 컴파일과 같은 기법을 통해 실행 시에만 얻을 수 있는 프로그램 분석 정보를 사용하여 높은 성능을 달성할 수 있다. 특히 객체 지향 언어나 스크립트 언어 같이 동적인 언어인 경우 효과적이다. 하지만 실행 시 프로그램 분석과 컴파일을 함께 수행하는데 추가 메모리 및 CPU 사이클이 필요한 단점이 있다. 따라서 AOT 컴파일은 이에 대한 보완책으로 사용되고 있다.

 

자바 9부터 도입

 

AOT compilation is one way of improving the performance of Java programs and in particular the startup time of the JVM. The JVM executes Java bytecode and compiles frequently executed code to native code. This is called Just-in-Time (JIT) Compilation. The JVM decides which code to JIT compile based on profiling information collected during execution.

While this technique enables the JVM to produce highly optimized code and improves peak performance, the startup time is likely not optimal, as the executed code is not yet JIT compiled. AOT aims to improve this so-called warming-up period. The compiler used for AOT is Graal.

 

 

 

To get the best of both worlds you have JIT and AOT compilers. JIT and AOT are to do with time hence the capital ’T’ in both of them, they stand for ‘Just In Time’ and ‘Ahead Of Time’ compilation. However JIT and AOT is the interpreter side where things which make for easier debugging. In other words we have a time frame of when something was executed. If there was an error we can stop in that time and notify the programmer of the error.

However there’s also another side to this which is compilation. When a user clicks a button in the ‘Just In Time’ program the function is left as a script until it’s invoked, just in time. Then the function is converted into machine code, when the function needs to be run again it’s now already compiled to machine code making it very fast executing. But note it’s left as a script initially until it needed, then it’s converted into machine code just in time.

AOT compilers will compile ‘Ahead Of Time’. This means when we invoke the script the compiler will ahead of time start converting the code into machine code. It doesn’t wait until the code needs be converted it just starts converting there and then. If it finds an error the AOT compiler will be better equipped at picking up some errors ahead of time and not just in time.

However because JIT and AOT have time involved in the program’s execution; we can monitor in a time frame when there is an error. Time and speed is the best mixture and most scripting languages use this technology today.

 

 

 

 

참고

 

자바스크립트 엔진의 JIT

https://meetup.toast.com/posts/77

 

•Hotspot이 별로 없는 고전적인 JavaScript 프로그램들에는 interpreter가 JITC보다 효율이 좋다.
•최근 많이 사용되는 compute-intensive한 JavaScript 프로그램들에는 JITC가 좋다.
•두 가지 성향의 코드에 대한 성능을 모두 만족하기 위해 최근 엔진들은 adaptive JITC를 채용한다.
•Adaptive JITC는 type profiling을 수행하므로, 변수의 type이 변하지 않는다면 높은 성능을 얻을 수 있다.

마지막 항목은 바꿔 말하면, 자주 반복되는 loop 안에서 수행 도중 변수의 type이 변하게 되면 많은 페널티가 발생하게 된다는 것입니다. 실제로 코드를 구현할 때 그런 상황은 거의 없겠지만, 알아두면 언제든 유용할 것입니다.

 

만약 성능이 좋은 JavaScript 코드를 만들고 싶다면, JavaScript 코드를 작성할 때 마치 C나 Java처럼 static typing 언어라고 생각하세요.
특히 array가 중요한데, 하나의 array에는 하나의 type만 넣어주는 것이 최고입니다!

 

자바스크립트 엔진의 최적화 기법 (1) - JITC, Adaptive Compilation : TOAST Meetup

자바스크립트 엔진의 최적화 기법 (1) - JITC, Adaptive Compilation

meetup.toast.com

https://www.youtube.com/watch?v=svJerixawV0

 

https://devblogs.microsoft.com/java/aot-compilation-in-hotspot-introduction/

 

AOT Compilation in HotSpot: Introduction | Java at Microsoft

Explore the AOT Compiler introduced in Java 9, its tradeoffs, its integration to the Tiered Compilation pipeline, how to use it, and some alternatives.

devblogs.microsoft.com

https://medium.com/jp-tech/try-out-jit-compiler-with-php-8-0-a020e6aeb3e5

 

Try out JIT compiler with PHP 8.0

You probably heard the news a few months ago that the JIT compiler will be added to PHP 8. If you haven’t heard, it is this poll. 90% of…

medium.com

 

'CS' 카테고리의 다른 글

Interpreter vs Compile  (0) 2020.02.01
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함