Skip to content

Commit ad63851

Browse files
Belosnegovanikpachoo
authored andcommitted
feat: gsoc 2024 wasm incremental compilation
1 parent 1efeb89 commit ad63851

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
119 KB
Loading
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: "Google Summer of Code 2024 – Incremental Compilation for the Kotlin/Wasm Compiler"
3+
date: 2025-01-21 20:01
4+
coverImage: "./cover.png"
5+
socialImage: "./social.png"
6+
---
7+
8+
9+
The Kotlin Foundation sponsored four projects for the [Google Summer of Code 2024](https://summerofcode.withgoogle.com/archive/2024/organizations/kotlin-foundation), and we are excited to announce the completion of the “Incremental Compilation for the Kotlin/Wasm Compiler” project\! JetBrains, a Kotlin Foundation member, provided mentoring support for this project.
10+
11+
This project enhanced the Kotlin-to-Wasm compiler with incremental compilation capabilities, reducing build times by allowing it to recompile only modified files. The contributor, Osama Ahmad, optimized and reused components from the Kotlin/JS backend while improving documentation and refactoring the codebase.
12+
13+
Thanks to [Osama Ahmad](https://www.linkedin.com/in/osamaahmad123/) and the mentor from JetBrains, [Igor Yakovlev](https://www.linkedin.com/in/igoriakovlev), for their great input\!
14+
15+
Explore [Kotlin/Wasm](https://kotlinlang.org/docs/wasm-overview.html).
16+
17+
## Introduction
18+
19+
Incremental compilation is a technique that helps increase compilation speed by recompiling only changed files instead of your whole program (a clean build). The Kotlin-to-Wasm compiler is used to support only clean builds, but during this project, we enhanced it to support incremental compilation, too.
20+
21+
## Goals of the project
22+
23+
The primary goals for the project were:
24+
25+
* To implement incremental compilation for the Wasm backend.
26+
* To reuse code as much as possible from the JavaScript backend.
27+
* To specialize and optimize incremental compilation for Wasm.
28+
29+
## Achievements
30+
31+
During the project, the following key achievements were made:
32+
33+
* **Incorporation of incremental compilation**: Now, the Wasm backend supports incremental compilation in addition to performing clean builds.
34+
* **Code reuse**: Many of the incremental compilation components were reused from the JavaScript backend and are specialized to work with the Wasm backend as well. One example is the CacheUpdater component, which determines the files for which we can use cached compiled files and the files that need to be recompiled, and updates the cached files as appropriate.
35+
* **Optimizations**: Multiple optimizations have been tried. Some are not worth the complexity they’ll introduce, such as trying to resolve struct field IDs in link time, but some have been successfully applied, such as the relocation of most bodiless declarations before starting the compilation process.
36+
* Documentation and refactoring: As a side effect of incorporating incremental compilation, the codebase became more complex and needed some refactoring and documentation for easier future development. One example is breaking the final linking function, `linkWasmCompiledFragments`, into multiple smaller and clearer functions, along with the necessary documentation.Newly introduced components such as `WasmSerializer` and `WasmDeserializer` are well documented, as well.
37+
38+
## Next steps
39+
40+
Through benchmarking, we found that the time taken to serialize and deserialize Wasm cached compiled files majorly contributes to linking time. This is because a single Wasm binary is produced, and each time a change is made, we need to load (deserialize) all cached compiled modules and link all of them in a single binary, even if only a single file in a single module was changed.
41+
42+
One solution to this problem is to implement per-module compilation, in which each Kotlin module is compiled to a standalone Wasm binary, and utilize Wasm features to link between the different module Wasm binaries. This way, we don’t need to load every module and link all of them into a single binary on each recompilation.
119 KB
Loading

0 commit comments

Comments
 (0)