JetBrains Platform
Plugin and extension development for JetBrains products.
Workspace Model
The Workspace Model, which serves as the internal storage for project models, has exited its experimental phase. Plugin developers can now safely access and modify the workspace model, benefiting from a centralized API, bulk updates, coroutines, and a persistent data structure.
This update is particularly relevant for developers working on build tool integration plugins, such as Maven, Gradle, BSP, Bazel, and others. Additionally, it will be useful for any plugin developers who interact with the JPS project model, known for classes like Module
, Library
, Facet
, ModuleManager
, IdeModifiableModelsProvider
, and others.
New Implementation of the JPS project model
Some time ago, we announced the reimplementation of project models. The IntelliJ platform still supports old interfaces like Module and ModuleManager to maintain compatibility with existing plugins. However, the new Workspace Model API is now also available for public use. Plugin developers are encouraged to update their code from the old API to the new API. More information on code migration can be found here.
The Workspace Model is designed to store any entities, including those defined by plugins. However, defining custom entities is still an experimental part of the API and will be released later. Currently, working with the Workspace Model is limited to using entities provided by the platform.
Benefits of the Workspace Model
The Workspace Model is designed as a persistent data structure, enabling it to handle various multithreading use cases. A snapshot of the storage is immutable and can be processed without a read lock. Batch operations like replaceBySource
and applyChangesFrom
are designed to support scenarios involving significant updates to the workspace model.
Compared to the previous implementation of the project models, the Workspace Model keeps everything in one storage, there is a single entry point for all updates, and there is no need to create multiple modifiable models as before. Also, as the old project model API now delegates to the Workspace Model, accessing the new API directly may improve the performance, especially for massive operations or big projects.
The flexibility of the Workspace Model allows the entire IntelliJ Platform to change the way we work with the project model. Rather than using specific managers, the subsystem can define extension points that can be contributed by other subsystems. For example, the new WorkspaceFileIndex
operates on entities provided by different parts of the IDE instead of directly using the ModuleManager
.
The event flow allows you to observe all changes occurring within the storage. Every update can be used to incrementally affect subsystems that depend on Workspace Model data. This feature has been utilized to remove some internal implementations of AdditionalLibraryRootsProvider
and DirectoryIndexExcludePolicy
, which were recalculated from scratch on each change of the project models, leading to improved performance of JetBrains IDEs.
Further evolution
The new Workspace model is already used in several places. The Rider IDE was the first client of the Workspace Model, and it still actively uses it. The Maven import was rewritten to the new API, giving a boost in performance. Different parts of GoLand, WebStorm, and the Kotlin plugin also started to use the new approach, gaining different benefits.
The next steps for the Workspace Model will focus on allowing plugin developers to define and use their own entities. This will make it possible to describe the project model of a build tool with specific entities that accurately reflect the structure of the project.
Currently, updates to the Workspace Model occur under a write lock. Future updates will eliminate this requirement, allowing updates to happen without acquiring any locks.
The IntelliJ platform still mostly uses the old API for working with the project models, however, all new code will be written using the new Workspace Model API. The subsystems that will benefit from the performance of the new API will also be migrated.