Kotlin logo

Kotlin

A concise multiplatform language developed by JetBrains

Ecosystem News

WebAssembly 用の Kotlin がアルファ版に

Kotlin Multiplatform の最新ターゲットプラットフォームである Kotlin/Wasm がアルファ版になりました! この変更について知っておくべき点をまとめました:

  • Kotlin/Wasm が JetBrains によってアルファ版に昇格され、皆さんにもお試しいただけるようになりました。 皆さんのフィードバックは、Kotlin を使ったウェブアプリケーションの未来を形成するのに役立ちます!
  • アルファリリースの Kotlin/Wasm は本番前のシナリオで使用できる状態ですが、まだ開発中の部分がたくさん残っています。 コミュニティの皆さんを頼りに Kotlin/Wasm に影響を及ぼす決定事項を通知し、優先順位を付けます。
  • Compose for Web(現時点では実験的機能)は Kotlin/Wasm を使用しています。 これら 2 つのテクノロジーを組み合わせることで、100% Kotlin のウェブアプリケーション用の宣言型ユーザーインターフェースを作成できます。

Kotlin/Wasm を使い始める

WebAssembly: Kotlin Multiplatform の最新ターゲット

WebAssembly はブラウザーをターゲットとする言語の標準コンパイルターゲット以上の地位を確立しつつあります! Kotlin/Wasm では Kotlin Multiplatform を通じてこの新しいターゲットを利用する機能を提供しています。 私たちは Kotlin 1.8.20 で Kotlin/Wasm を実験的テクノロジーとして導入した後、改良に改良を重ねました。

Kotlin は自動的にメモリを管理する言語であるため、最近フェーズ 4(標準化)に達したガベージコレクションの提案に基づいて構築されています。 つまり、今では多くの主要ブラウザーでデフォルトで使用できます。 たとえば、Chrome と Firefox の最近のバージョンでは何も調整しなくても Kotlin/Wasm アプリケーションを実行できます。 Safari は現時点では Wasm GC をサポートしていませんが、JavaScriptCore で必要な機能の実装はすでに進行中です。

はじめの一歩: Kotlin/Wasm

Kotlin/Wasm コミュニティに参加する

Kotlin/Wasm を使い始めるには、「はじめに」ページを参照するのが簡単です。 このテクノロジーの概要と独自の Kotlin/Wasm アプリケーションをセットアップするための手順がそこに記載されています。 また、ブラウザーでの使用方法や Compose Multiplatform との併用など、Kotlin/Wasm のさまざまな側面を紹介するプロジェクトやサンプルプロジェクトへのリンクもあります。

Kotlin/Wasm がアルファになりました: テクノロジーとサンプルプロジェクトを確かめてください

Kotlin Playground も Kotlin/Wasm をサポートするようになったため、ブラウザーで直接初めての WebAssembly コードスニペットを書き、Kotlin/Wasm が提供する機能を確かめることができます。

WebAssembly で最初の「Hello World」サンプルを超えるものを作成できるよう、Kotlin/Wasm に `kotlinx` ライブラリ一式も導入しています。 このライブラリには kotlinx-atomicfukotlinx.coroutineskotlinx.serializationkotlinx-datetime、および kotlinx-io が含まれています。

ネットワーク対応アプリケーションを構築するための JetBrains フレームワークである Ktor も WebAssembly に導入されます。 次のリリースでは、Ktor の HTTP クライアントを使用して Kotlin/Wasm コードからネットワークリクエストを直接送信できるようになります。

Compose Multiplatform: Kotlin/Wasm を使用

Kotlin/Wasm は特定の UI フレームワークに縛られていません。 ブラウザーで Kotlin コードを実行する汎用的な手段ですが、 Google の Jetpack Compose をベースにした JetBrains の宣言型マルチプラットフォーム UI ツールキットである Compose Multiplatform の実験的なウェブターゲットに使用される基盤テクノロジーです。 ウェブ用の Compose Multiplatform はキャンバスベースのレンダリングを採用しているため、他のプラットフォームで使用するのと同じレイアウトとコンポーネントを使用できます。 初期状態では Material と Material 3 のデザインコンポーネントが搭載されています。

Compose Multiplatform を使うと、最も重要なプラットフォームである Android と iOS、デスクトップ、さらにはブラウザー(Kotlin/Wasm の力によって実現)をターゲットとする共有アプリケーションをビルドできます。 独自の共有 UI を作成し始める場合、同じように Kotlin/Wasm ターゲットを実験的にサポートしている Kotlin Multiplatform Web ウィザードを使用してプロジェクトを生成できます。

パフォーマンス

WebAssembly は言語用のコンパイルターゲットとしてゼロからデザインされているため、Kotlin コンパイラーはソースコードをパフォーマンスに優れた WebAssembly バイトコードに変換できます。 弊社では Kotlin/Wasm に定期的にベンチマークを実行し、実行時のパフォーマンスを確認しています。 Kotlin/Wasm はまだアルファ版であるため、継続的にパフォーマンス改善が行われてはいますが、以下のように Kotlin/Wasm はほぼすべてのマクロベンチマークですでに Kotlin/JS のパフォーマンスを上回っています。

同様に、Kotlin/Wasm で動作する Compose Multiplatform は JVM 上で同じアプリケーションを実行する場合と同等の実行速度となっており、すでに有望なパフォーマンス特性を示しています。

AnimatedVisibility: Wasm の実行時間は JS 実装の 0.5 倍
LazyGrid: Wasm の実行時間は JS 実装の 0.5 倍
VisualEffects: Wasm の実行時間は JS 実装の 0.5 倍

これらのベンチマーク結果は弊社が Google Chrome の最近のバージョンでテストした結果ですが、他のブラウザーでも同様の結果が出ています。

進行中の作業

現在アルファ版のテクノロジーである Kotlin/Wasm は急速に進化しており、活発に改善と強化が行われています。 そのため、まだ開発が進行中の分野がいくつかあります。

現時点では Kotlin/Wasm のデバッグサポートには制限があり、今後はその機能を改善していく予定です。 また、ウェブをターゲットとする際にはバンドルのサイズが重要であることも認識しているため、特に Compose Multiplatform プロジェクトを対象にコンパイラーが生成する出力の最適化を進めたいと考えています。

WebAssembly は進化し続けていますが、弊社は スタックの切り替えスレッド化 などの新しい提案が公開されるたびにそのメリットを利用したいと考えています。 また、WebAssembly Component Model のサポートを Kotlin に導入するための作業に取り組んでいます。これは、相互運用可能な Wasm ライブラリとアプリケーションのビルドが可能にするものです。 さらに、WASI(WebAssembly System Interface)のサポートなど、Kotlin/Wasm をブラウザー外部の素晴らしい開発ターゲットにする作業にも取り組んでいます。 弊社は WebAssembly Community Group の一員として WebAssembly VM のベンダーと積極的に連携し、Kotlin/Wasm が実行場所に関係なく優れたエクスペリエンスを確実に提供できるように努めています。

優れた開発者エクスペリエンスをユーザーに提供し、パフォーマンスとバンドルサイズの要件を満たせるようにすることが目標です。 これらの分野で進展があるたびに、更新情報と詳細な情報を必ずお伝えします!

コミュニティに参加して更新情報を入手し、フィードバックを共有しましょう!

Kotlin/Wasm コミュニティに参加する

Kotlin/Wasm に期待しているチームや他の開発者とつながりたい方は、Kotlin Slack でのディスカッションにご参加ください(こちらで招待を受けてください)。 #webassembly チャンネルでは、Kotlin と WebAssembly のすべてに関するディスカッションをご覧いただけます。

Kotlin/Wasm はアルファ段階にあるため、弊社はユーザーの要件に基づいてテクノロジーを進化させ続けたいと思っています。 問題の報告や足りないと思われる API のご連絡、実装を希望する機能のリクエストにより、改善にご協力ください。 要件を伝えるには、YouTrack の Kotlin プロジェクトに課題を追加してください。

Kotlin の次のステップに踏み出せたことを嬉しく思っており、Kotlin/Wasm で皆さんが何を作成されるのかを楽しみにしています!

Kotlin/Wasm の実際の動作をご覧ください!

2023 年 12 月 12 日火曜日に Kotlin 公式の YouTube チャンネルで Kotlin/Wasm チームリーダーの Zalim Bashorov が「Kotlin and WebAssembly: Unleashing Cross-Platform Power(Kotlin と WebAssembly: クロスプラットフォームの力を解放)」というタイトルでライブセッションを開催しました。こちらから動画をご覧ください。

以下もご確認ください

Discover more

Ecosystem News

WebAssembly용 Kotlin, 알파 버전 출시

최신 Kotlin Multiplatform 타깃 플랫폼인 Kotlin/Wasm이 알파 단계로 올라섰습니다! 이 변화에서 알아야 할 사항을 간략히 요약해 드립니다.

  • JetBrains는 Kotlin/Wasm을 알파 단계로 올려 여러분이 직접 사용해 볼 수 있도록 준비했습니다. 여러분의 의견은 Kotlin을 사용한 웹 애플리케이션 구축의 미래를 만들어가는 데 도움이 됩니다!
  • 알파 릴리스의 Kotlin/Wasm은 사전 프로덕션 시나리오에서 사용할 준비를 마쳤지만 아직 작업이 진행 중인 부분이 많습니다. Kotlin/Wasm에 관한 의사 결정에서 고려하고 우선순위를 정해야 할 사항을 수집하기 위해 커뮤니티의 참여가 필요합니다.
  • Compose for Web(현재 실험적 단계)은 Kotlin/Wasm을 기반으로 합니다. 두 기술을 함께 사용하면 웹 애플리케이션을 위한 선언적 사용자 인터페이스를 100% Kotlin으로 만들 수 있습니다.

Kotlin/Wasm 시작하기

WebAssembly: 최신 Kotlin Multiplatform 타깃

WebAssembly는 브라우저와 그 이상을 대상으로 하는 언어의 표준 컴파일 타깃으로 자리잡고 있습니다. Kotlin/Wasm을 사용하면 Kotlin Multiplatform을 통해 이 새로운 타깃을 활용할 수 있습니다. Kotlin 1.8.20에서 실험적 기술로 Kotlin/Wasm을 처음 도입한 이후 이를 계속해서 개선하고 다듬어 왔습니다.

Kotlin은 자동으로 메모리 관리되는 언어이기 때문에 최근 4단계(표준화)에 도달한 가비지 컬렉션 제안을 기반으로 삼습니다. 즉, 이제 다수의 주요 브라우저에서 기본적으로 이를 사용할 수 있습니다. 예를 들어, Chrome과 Firefox의 최신 버전에서는 별다른 조정 없이 Kotlin/Wasm 애플리케이션을 실행할 수 있습니다. Safari는 현재 아직 Wasm GC를 지원하지는 않지만 JavaScriptCore에 필요한 기능 구현이 이미 진행 중입니다.

Kotlin/Wasm 시작하기

Kotlin/Wasm 커뮤니티에 참여

Kotlin/Wasm을 시작하는 쉬운 방법은 시작하기 페이지를 살펴보는 것입니다. 여기에서는 기술 개요와 Kotlin/Wasm 애플리케이션을 설정하는 방법에 대한 지침을 확인할 수 있습니다. 또한 Compose Multiplatform 등과 함께 브라우저에서 Kotlin/Wasm을 사용하는 방법을 보여주는 데모를 포함하여 Kotlin/Wasm의 다양한 측면을 보여주는 프로젝트 및 예시 프로젝트 링크도 볼 수 있습니다.

Kotlin/Wasm 알파 버전: 기술을 자세히 살펴보고 예제 프로젝트 보기

이제 Kotlin Playground에서 Kotlin/Wasm도 지원합니다. 즉, 브라우저에서 바로 첫 WebAssembly 코드 스니펫을 작성하고 Kotlin/Wasm이 제공하는 기능을 살펴볼 수 있습니다.

사용자가 첫 “Hello World” 예시를 마치고 WebAssembly의 활용 수준을 높일 수 있도록 ‘kotlinx’ 라이브러리 모음을 Kotlin/Wasm에 도입합니다. 여기에는 kotlinx-atomicfu, kotlinx.coroutines, kotlinx.serialization, kotlinx-datetimekotlinx-io가 포함됩니다.

네트워크 애플리케이션 구축을 위한 JetBrains 프레임워크인 Ktor도 WebAssembly에 제공됩니다. 다음 릴리스에서는 Ktor의 HTTP 클라이언트를 사용하여 Kotlin/Wasm 코드에서 바로 네트워크 요청을 수행할 수 있을 것입니다.

Compose Multiplatform: Kotlin/Wasm 기반

Kotlin/Wasm은 특정 UI 프레임워크에 바인딩되지 않습니다. 이는 브라우저에서 Kotlin 코드를 실행하는 일반적인 방법인 동시에, Google의 Jetpack Compose를 기반으로 하는 JetBrains의 선언적 멀티플랫폼 UI 툴킷인 Compose Multiplatform의 실험적 웹 타깃을 위한 기본 기술입니다. 웹용 Compose Multiplatform은 캔버스 기반 렌더링을 사용합니다. 즉, 다른 플랫폼에서와 동일한 레이아웃과 구성 요소를 사용할 수 있습니다. 기본적으로 Material 및 Material 3 디자인 구성 요소가 함께 제공됩니다.

Compose Multiplatform을 사용하면 Android, iOS, 데스크톱, 브라우저(Kotlin/Wasm의 강력한 기능 덕분에) 등 가장 중요한 플랫폼을 타깃으로 하는 공유 애플리케이션을 구축할 수 있습니다. 자신만의 공유 UI를 빌드하려는 경우, 이제 Kotlin/Wasm 타깃도 실험적으로 지원하는 Kotlin Multiplatform 웹 마법사를 사용하여 프로젝트를 생성할 수 있습니다.

성능

WebAssembly는 처음부터 언어에 대한 컴파일 타깃으로 설계되었기 때문에 Kotlin 컴파일러가 소스 코드를 성능 기준에 맞는 WebAssembly 바이트코드로 변환할 수 있습니다. JetBrains는 Kotlin/Wasm의 런타임 성능을 보장하기 위해 정기적으로 벤치마크를 실행합니다. Kotlin/Wasm은 아직 알파 버전이므로 성능 개선을 위한 팀 작업이 계속되고 있지만 아시다시피 Kotlin/Wasm은 이미 거의 모든 매크로 벤치마크에서 Kotlin/JS보다 성능이 뛰어납니다.

마찬가지로, Kotlin/Wasm에서 실행되는 Compose Multiplatform은 이미 JVM에서 동일한 애플리케이션을 실행하는 것과 비슷한 실행 속도를 나타내며 유망한 성능 특성을 보여줍니다.

AnimatedVisibility: Wasm은 JS 구현 시간의 0.5배 소요
LazyGrid: Wasm은 JS 구현 시간의 0.5배 소요
VisualEffects: Wasm은 JS 구현 시간의 0.5배 소요

이러한 벤치마크 결과는 최신 버전의 Google Chrome에서 테스트한 결과이지만 테스트한 다른 브라우저에서도 비슷한 결과가 관찰되었습니다.

진행 중인 작업

알파 단계의 기술로서 Kotlin/Wasm은 빠르게 발전하고 있으며 개선과 기능 강화를 위한 팀의 노력도 한창이므로 아직 작업이 진행 중인 부분이 많습니다.

현재, Kotlin/Wasm의 디버그 지원이 제한적이며 앞으로 기능을 개선하기 위해 노력하고 있습니다. 또한 웹을 타기팅할 때 번들 크기가 중요한 요소라는 점을 알기에, 특히 Compose Multiplatform 프로젝트의 경우 컴파일러에서 생성된 출력을 더욱 최적화하려고 합니다.

WebAssembly가 계속 발전함에 따라 스택 전환, 스레딩 등 새로운 제안이 들어오는 대로 도입할 생각입니다. 또한, Kotlin에 WebAssembly 구성 요소 모델에 대한 지원을 도입하기 위해 노력하고 있습니다. 이를 통해 상호 운용 가능한 Wasm 라이브러리 및 애플리케이션을 구축할 수 있게 될 것입니다. 그뿐 아니라 WebAssembly 시스템 인터페이스인 WASI에 대한 지원을 포함하여 Kotlin/Wasm을 브라우저 외부 개발을 위한 탁월한 타깃으로 만들기 위한 작업도 진행 중입니다. WebAssembly 커뮤니티 그룹의 일원으로서 JetBrains는 WebAssembly VM 공급업체와 적극적으로 협력하여 Kotlin/Wasm을 실행하는 위치에 관계없이 훌륭한 경험을 제공할 수 있도록 하기 위해 노력하고 있습니다.

JetBrains의 목표는 여러분에게 뛰어난 개발자 경험을 제공하고 성능과 번들 크기 측면에서 요구 사항이 충족되도록 하는 것입니다. 이러한 작업이 진전을 이루면 업데이트를 제공하고 더 많은 정보를 공유하겠습니다!

커뮤니티에 가입하여 업데이트를 받고 피드백을 공유하세요!

Kotlin/Wasm 커뮤니티에 참여하기

Kotlin/Wasm에 관심이 있는 팀 및 다른 개발자들과 소통하고 싶다면 Kotlin Slack 토론에 참여해 보세요(여기에서 초대 받기). #webassembly 채널에서 Kotlin과 WebAssembly에 관한 모든 토론을 찾을 수 있습니다.

Kotlin/Wasm은 이제 알파 버전이며, 여러분들의 요구 사항에 따라 기술을 계속해서 발전시키고자 합니다. 문제를 보고하거나, 누락된 API에 관해서 알려주시거나, 원하는 기능을 요청하면 저희에게 큰 도움이 됩니다. 이러한 내용을 알려주실 때에는 YouTrack의 Kotlin 프로젝트에 이슈를 추가하면 됩니다.

JetBrains는 즐거운 마음으로 Kotlin의 다음 단계를 준비하고 있으며 Kotlin/Wasm이 얼마나 멋진 결과물을 만들어낼지 기대됩니다!

Kotlin/Wasm이 실제 어떻게 사용되는지 확인하세요!

2023년 12월 12일 화요일, Kotlin/Wasm 팀장인 Zalim Bashorov가 공식 Kotlin YouTube 채널에서 Kotlin 및 WebAssembly: Unleashing Cross-Platform Power(크로스 플랫폼의 강력한 성능 활용)라는 제목의 라이브 세션을 진행했습니다. 앞으로의 소식도 놓치지 않고 시청하려면 가입하여 알림을 받으세요.

기타 참고 자료

게시물 원문 작성자

Discover more

Ecosystem News

适用于 WebAssembly 的 Kotlin 进入 Alpha 阶段

Kotlin/Wasm 是新推出的 Kotlin Multiplatform 目标平台,现已达到 Alpha 状态! 以下是值得注意的更改:

  • JetBrains 已将 Kotlin/Wasm 提升到 Alpha 版本,让您可以亲自上手尝试。 您的反馈将影响使用 Kotlin 构建 Web 应用程序的未来!
  • 作为 Alpha 版本,Kotlin/Wasm 已经可以在预生产场景中使用,但许多方面仍待完善。 我们需要社区的帮助来确定 Kotlin/Wasm 的相关决策并确定其优先级。
  • Compose for Web(目前处于实验阶段)由 Kotlin/Wasm 提供支持。 两种技术互相配合,让您完全使用 Kotlin 为 Web 应用程序创建声明式用户界面。

开始使用 Kotlin/Wasm

WebAssembly:最新的 Kotlin Multiplatform 目标

对于以浏览器为目标的语言,WebAssembly 正在成为其标准编译目标。 借助 Kotlin/Wasm,您能够通过 Kotlin Multiplatform 使用这个新目标。 我们最初在 Kotlin 1.8.20 中作为实验性技术引入 Kotlin/Wasm,此后对其进行了改进和完善。

Kotlin 是一种自动内存管理语言,建立在最近达到第 4 阶段(标准化)垃圾回收提案的基础上, 已在许多主流浏览器中默认启用。 例如,最新版本的 Chrome 和 Firefox 都可以运行 Kotlin/Wasm 应用程序,无需任何调整。 虽然 Safari 尚未支持 Wasm 垃圾回收,但 JavaScriptCore 中必需功能的实现已在推进。

Kotlin/Wasm 使用入门

加入 Kotlin/Wasm 社区

开始使用 Kotlin/Wasm 的便捷方式是查看使用入门页面。 该页面提供了技术概览以及设置 Kotlin/Wasm 应用程序的说明。 您还会看到项目和展示 Kotlin/Wasm 不同方面的示例项目链接,其中的一些项目阐释了如何在浏览器中使用以及配合 Compose Multiplatform 等。

Kotlin/Wasm 进入 Alpha 阶段:详细探索技术和查看示例项目

Kotlin Playground 现在也支持 Kotlin/Wasm,您可以直接在浏览器中编写第一个 WebAssembly 代码段并探索 Kotlin/Wasm 的功能。

为了帮助您超越初学 WebAssembly 时的“Hello World”示例,我们还将 `kotlinx` 库套件引入 Kotlin/Wasm, 包括 kotlinx-atomicfukotlinx.coroutineskotlinx.serializationkotlinx-datetimekotlinx-io

用于构建网络应用程序的 JetBrains 框架 Ktor 也即将登陆 WebAssembly。 在下一个版本中,您将能够使用 Ktor 的 HTTP 客户端直接从 Kotlin/Wasm 代码发起网络请求。

Compose Multiplatform:由 Kotlin/Wasm 提供支持

Kotlin/Wasm 未绑定到任何特定 UI 框架, 是在浏览器中运行 Kotlin 代码的通用方式。 不过,它是 Compose Multiplatform 实验性 Web 目标的底层技术,Compose Multiplatform 是 JetBrains 基于 Google 的 Jetpack Compose 打造的声明式多平台 UI 工具包。 Compose Multiplatform for Web 使用基于画布的渲染,您可以使用与其他平台上相同的布局和组件。 它直接配备了 Material 和 Material 3 设计组件。

借助 Compose Multiplatform,您可以构建以最重要平台为目标的共享应用:Android 和 iOS、桌面,以及浏览器(得益于 Kotlin/Wasm 的强大功能)。 要开始构建您自己的共享 UI,您可以使用 Kotlin Multiplatform Web 向导生成项目,向导现在也实验性地支持 Kotlin/Wasm 目标。

性能

WebAssembly 从一开始就被设计为语言的编译目标,这意味着 Kotlin 编译器可以将源代码转换为高性能 WebAssembly 字节码。 我们定期在 Kotlin/Wasm 上运行基准测试,确保其运行时性能。 由于 Kotlin/Wasm 仍处于 Alpha 阶段,团队将继续推动性能改进,但 Kotlin/Wasm 在几乎所有宏基准测试中都已经优于 Kotlin/JS:

同样,在 Kotlin/Wasm 上运行的 Compose Multiplatform 已经表现出良好的性能特征,执行速度与在 JVM 上运行的相同应用程序相当:

AnimatedVisibility:Wasm 耗时为 JS 实现时间的一半
LazyGrid:Wasm 耗时为 JS 实现时间的一半
VisualEffects:Wasm 耗时为 JS 实现时间的一半

这些基准测试结果来自我们在最新版本 Google Chrome 中的测试,但我们在测试的其他浏览器中也观察到相似结果。

正在推进的工作

作为一项处于 Alpha 阶段的技术,Kotlin/Wasm 正迅速发展,团队正在全力开发改进和增强。 因此,仍有许多领域尚待完善。

目前,Kotlin/Wasm 中的调试支持有限,我们正在努力改进其功能。 我们也意识到,在以 Web 为目标时,捆绑包大小是一个重要因素,我们希望进一步优化编译器生成的输出,特别是对于 Compose Multiplatform 项目。

随着 WebAssembly 持续发展,我们希望在新提案到来时加以利用 – 无论是堆栈切换线程,还是其他。 我们还在向 Kotlin 引入对 WebAssembly Component Model 的支持,这将用于构建可互操作的 Wasm 库和应用程序。 我们还在努力使 Kotlin/Wasm 成为浏览器之外开发的良好目标,包括对 WASI (WebAssembly System Interface) 的支持。 作为 WebAssembly Community Group 的一部分,通过与 WebAssembly VM 的供应商积极合作,我们希望确保 Kotlin/Wasm 无论在何处都能提供出色的体验。

我们的目标是为您提供卓越的开发者体验,并确保其在性能和捆绑包大小方面满足您的要求。 随着我们取得进展,我们将为您提供动态并分享更多信息!

加入社区以获取动态并分享反馈!

加入 Kotlin/Wasm 社区

如果您想与其他对 Kotlin/Wasm 感兴趣的团队和开发者交流,我们邀请您加入 Kotlin Slack 上的讨论(在此处获取邀请)。 在 #webassembly 频道中,您可以找到有关 Kotlin 和 WebAssembly 的讨论。

Kotlin/Wasm 处于 Alpha 阶段,我们希望确保根据用户的需求继续发展这项技术。 报告问题、告诉我们您认为缺少的 API,以及请求您希望看到的功能,帮助我们为您做出改进。 您可以向 Kotlin YouTrack 项目添加问题。

我们很高兴与 Kotlin 共同迈出下一步,也期待看到您使用 Kotlin/Wasm 的开发成果!

查看 Kotlin/Wasm 的实际运作!

2023 年 12 月 12 日星期二,Kotlin/Wasm 团队主管 Zalim Bashorov 在官方 Kotlin YouTube 频道上进行了题为 Kotlin and WebAssembly: Unleashing Cross-Platform Power 的直播! 您可以点击此页面收看回放。

另请参阅

 

本博文英文原作者:

Discover more

Ecosystem News

Kotlin for WebAssembly Goes Alpha

Kotlin/Wasm, the newest Kotlin Multiplatform target platform, has reached Alpha status! Here’s what you need to know about this change at a glance:

  • JetBrains has promoted Kotlin/Wasm to Alpha, making it ready for you to try for yourself. Your feedback will help shape the future of building web applications with Kotlin!
  • As an Alpha release, Kotlin/Wasm is ready for you to use in pre-production scenarios, but it still has many areas that are works in progress. We rely on the community to help inform and prioritize the decisions influencing Kotlin/Wasm.
  • Compose for Web (currently experimental) is powered by Kotlin/Wasm. Together, the two technologies allow you to create declarative user interfaces for web applications in 100% Kotlin.

Get started with Kotlin/Wasm

WebAssembly: The newest Kotlin Multiplatform target

WebAssembly is establishing itself as the standard compilation target for languages targeting the browser – and beyond! With Kotlin/Wasm, we’re giving you the ability to make use of this new target via Kotlin Multiplatform. We first introduced Kotlin/Wasm in Kotlin 1.8.20 as an experimental technology, and have since improved and refined it.

Because Kotlin is an automatically memory-managed language, it builds on the garbage collection proposal, which recently reached phase 4 (standardization). That means it is now enabled by default in a number of major browsers. For example, recent versions of both Chrome and Firefox can run Kotlin/Wasm applications without any required adjustments. While Safari currently doesn’t support Wasm GC yet, implementation of the required functionality in JavaScriptCore is already underway.

Getting started with Kotlin/Wasm

Join the Kotlin/Wasm community

An easy way to get started with Kotlin/Wasm is to take a look at the Getting Started page. Here, you’ll find an overview of the technology and instructions on how to set up your own Kotlin/Wasm application. You’ll also see projects and links to example projects that show off different facets of Kotlin/Wasm, including those that illustrate how to use it in the browser, together with Compose Multiplatform, and more.

Kotlin/Wasm goes Alpha: explore the technology in detail and see example projects

The Kotlin Playground now also has support for Kotlin/Wasm, meaning you can write your first WebAssembly code snippets right in your browser, and explore what Kotlin/Wasm has to offer.

To help you go beyond your first “Hello World” examples with WebAssembly, we are also bringing the `kotlinx` suite of libraries to Kotlin/Wasm. This includes kotlinx-atomicfu, kotlinx.coroutines, kotlinx.serialization, kotlinx-datetime, and kotlinx-io.

Ktor, the JetBrains framework for building networked applications, is also coming to WebAssembly. With the next release, you’ll be able to use Ktor’s HTTP clients to make network requests right from your Kotlin/Wasm code.

Compose Multiplatform: Powered by Kotlin/Wasm

Kotlin/Wasm isn’t bound to any specific UI framework. It’s a general way of running your Kotlin code in the browser. However, it is the underlying technology for the experimental web target of Compose Multiplatform, the declarative multiplatform UI toolkit by JetBrains based on Google’s Jetpack Compose. Compose Multiplatform for Web uses canvas-based rendering, meaning that you can use the same layouts and components as you would on other platforms. Out of the box, it comes with the Material and Material 3 design components.

With Compose Multiplatform, you can build shared applications that target the most important platforms: Android and iOS, desktop, and – thanks to the power of Kotlin/Wasm – the browser. To start building your own shared UIs, you can generate a project using the Kotlin Multiplatform Web Wizard, which now also experimentally supports the Kotlin/Wasm target.

Performance

WebAssembly is designed from the ground up as a compilation target for languages, meaning the Kotlin compiler can convert your source code into performant WebAssembly bytecode. We regularly run benchmarks on Kotlin/Wasm to ensure its runtime performance. Since Kotlin/Wasm is still in Alpha, the team continues to work on performance improvements, but as you can see, Kotlin/Wasm already outperforms Kotlin/JS in almost all of our macro benchmarks:

Likewise, Compose Multiplatform running on Kotlin/Wasm already shows promising performance characteristics, with execution speed comparable to that of running the same application on the JVM:

These benchmark results come from our testing in a recent version of Google Chrome, but we observed similar results in other browsers we tested.

What’s in the works

As a technology in Alpha, Kotlin/Wasm is evolving rapidly, and the team is busy making improvements and enhancements. As such, there are still a number of areas that are works in progress.

Currently, the debugging support in Kotlin/Wasm is limited, and we’re working on improving its capabilities going forward. We’re also aware that bundle size is an important factor when it comes to targeting the web, and we want to further optimize the outputs generated by the compiler, especially for Compose Multiplatform projects.

As WebAssembly continues evolving, we want to take advantage of new proposals as they arrive – whether that’s stack switching, threading, or others. We’re also working on introducing support for the WebAssembly Component Model to Kotlin, which will enable you to build interoperable Wasm libraries and applications. We’re also still in the process of making Kotlin/Wasm an awesome target for development outside of the browser, including support for WASI, the WebAssembly System Interface. As a part of the WebAssembly Community Group, and by actively collaborating with vendors of WebAssembly VMs, we’re striving to ensure that Kotlin/Wasm provides a great experience no matter where you’re running it.

Our goal is to provide an excellent developer experience for you, and make sure that it meets your requirements in terms of performance and bundle size. As we make progress on these fronts, we’ll make sure to provide you with updates and share more information!

Join the community to get updates and share your feedback!

Join the Kotlin/Wasm community

If you want to connect with the team and other developers excited about Kotlin/Wasm, we invite you to join the discussion on the Kotlin Slack (get your invite here). In the #webassembly channel, you can find discussions about everything Kotlin and WebAssembly.

Kotlin/Wasm is in Alpha, and we want to make sure we continue evolving the technology based on your requirements. Help us help you by reporting problems, telling us about APIs that you feel are missing, and requesting features you’d like to see. You can do so by adding issues to the Kotlin YouTrack project.

We’re excited to take this next step with Kotlin and look forward to seeing what you’ll create with Kotlin/Wasm!

See Kotlin/Wasm in action!

On Tuesday, December 12, 2023, Kotlin/Wasm Team Lead Zalim Bashorov will present a live session entitled Kotlin and WebAssembly: Unleashing Cross-Platform Power on the official Kotlin YouTube channel! To make sure you don’t miss it, sign up to receive notifications.

See also

Discover more