Optimize DefaultDocumentBuilder to Rebuild Linked Documents Only on Save (Performance Improvement for Large Workspaces) #2061
Replies: 1 comment 1 reply
-
|
Hey @we-wake-act21,
This is a perfect use case for overriding
Well, the fact that the individual documents run out-of-sync can be seen as a inconsistency in itself. The main issue is that references from other documents (that are yet to be rebuilt) to the documents that already have been reparsed are completely stale. Meaning that you are targeting AST nodes that longer exist in the given document. This in itself isn't that problematic, you just need to be aware of it in case you run something like a cyclic dependency resolution between files where file
The framework offers a |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi team,
I'm currently exploring ways to optimize the document build process for large workspaces and wanted to get some feedback or suggestions on the approach I’m taking.
Background
In Langium, the
updatemethod of theDefaultDocumentBuilderis triggered on every file content change.By default, this method:
LangiumDocument.This behavior works fine for small workspaces. However, in large workspaces, every update triggers a costly rebuild process, as all linked documents go through the entire lifecycle even for minor changes.
Goal
I want to limit the rebuild of linked documents only when a document is saved, rather than on every content change.
This should significantly improve performance for large projects by reducing unnecessary rebuilds during typing or editing.
Current Approach
I’ve implemented a custom
DocumentBuilderthat modifies this behavior:Override
shouldRelinkI modified
shouldRelinkto returnfalse, ensuring that only the modified document is rebuilt during normal updates.Listen to
onDidSaveeventsI’ve added an event listener on
TextDocuments.onDidSaveto trigger a full rebuild of linked documents when a document is saved:This ensures that:
(onUpdate), only the active document is rebuilt.Question
Is this a correct and recommended approach to achieve the desired optimization?
Or is there a more appropriate or built-in mechanism in Langium to control when linked documents are rebuilt (e.g., hooks, configuration options, or lifecycle events)?
I’d appreciate any insights on:
shouldRelink.Beta Was this translation helpful? Give feedback.
All reactions