eclipse-emfcloud / ecore-glsp

ecore-glsp
Other
32 stars 25 forks source link

Performance improvements with new version of GLSP and Sprotty #92

Open planger opened 3 years ago

planger commented 3 years ago

In order to improve performance, Sprotty introduced a mechanism that allows to check whether a model element is actually visible in the current viewport and, depending on visibility, should be rendered or not. https://github.com/eclipse/sprotty/commit/e74b908caead9970a4728c13218390ca62314ade Preventing the rendering for model elements that aren't visible anyway for sure has a positive impact on performance. So the visibility should also be considered in Ecore's view renderings, once upgraded to the latest version of GLSP and Sprotty.

In addition, consider to skip rendering of certain detail elements if the zoom level is very low (ie zoomed out a lot). With that also the performance in showing very large diagrams from a very far perspective can be significantly improved by avoiding to render e.g. attributes or edges, if they won't be readable due to the zoom factor anyway. The zoom factor can easily be determined with the following code. Also in another project we've increased the font size of class titles based on the zoom factor to keep the important details (such as the title of an EClass) readable even if zoomed out a lot.


   const textStyle = { fontSize: `${this.computeNormalizedFontSize(node)}pt` };

   ...
   <text style={textStyle} ... />
   ...

    protected computeNormalizedFontSize(node: Readonly<SChildElement>) {
        const viewPort = findParentByFeature(node, isViewport);
        const zoomFactor = viewPort ? viewPort.zoom : 1;
        const minSize = 5;
        const maxSize = 20;
        const normalizedFontSize = Math.max(Math.min(10 / zoomFactor, maxSize), minSize);
        return normalizedFontSize;
    }