<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0"
     xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xml:base="https://specificlanguages.com/">
  <channel>
    <title>Performance on Specific Languages</title>
    <link>https://specificlanguages.com/categories/performance/</link>
    <description>Recent content in Performance on Specific Languages</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <managingEditor>sergej@specificlanguages.com (Sergej Koščejev)</managingEditor>
    <webMaster>sergej@specificlanguages.com (Sergej Koščejev)</webMaster>
    <lastBuildDate>Wed, 26 Jan 2022 09:20:50 +0100</lastBuildDate>
    
    <atom:link href="https://specificlanguages.com/categories/performance/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Speeding up model checks with Scope Cache</title>
      <link>https://specificlanguages.com/posts/2022-01/26-speeding-up-model-checks-with-scope-cache/</link>
      <pubDate>Wed, 26 Jan 2022 09:20:50 +0100</pubDate>
      <author>sergej@specificlanguages.com (Sergej Koščejev)</author>
      <guid>https://specificlanguages.com/posts/2022-01/26-speeding-up-model-checks-with-scope-cache/</guid>
      <description>&lt;p&gt;Model checks on large models can take several minutes. Profiling one of such long-running checks, I found that it spent
minutes checking reference scopes. The model I was checking had about 130 &lt;em&gt;thousand&lt;/em&gt; references and a scope had to be
computed and checked for each one. Very often these scopes would turn out to be identical, but there was no way to avoid
recomputing them over and over.&lt;/p&gt;
&lt;p&gt;The MPS team must have encountered of these problems as well, since the MPS 2021.2
&lt;a href=&#34;https://www.jetbrains.com/mps/whatsnew/#optimized-reference-scope&#34;&gt;introduced&lt;/a&gt; an enhancement to the constraints
language to cache scopes.&lt;/p&gt;</description>
      <content:encoded xml:base="https://specificlanguages.com/posts/2022-01/26-speeding-up-model-checks-with-scope-cache/"><![CDATA[ <p>Model checks on large models can take several minutes. Profiling one of such long-running checks, I found that it spent
minutes checking reference scopes. The model I was checking had about 130 <em>thousand</em> references and a scope had to be
computed and checked for each one. Very often these scopes would turn out to be identical, but there was no way to avoid
recomputing them over and over.</p>
<p>The MPS team must have encountered of these problems as well, since the MPS 2021.2
<a href="https://www.jetbrains.com/mps/whatsnew/#optimized-reference-scope">introduced</a> an enhancement to the constraints
language to cache scopes.</p>
<p>Unfortunately, I couldn&rsquo;t use the new feature. First, my project is still using MPS 2020.3 and upgrading to 2021.2 looks
to be a matter of distant future. Second, I wanted to choose my own cache keys but the new language concepts only
support caching some predefined scope pieces. Third, the scope cache in MPS 2021.2 is only accessible from the
constraints language, but half of the references in my large model used inherited scopes (the <code>ScopeProvider</code> mechanism)
and the code computing the scopes would live in the behavior model where the new language could not be used.</p>
<p>However, I liked the underlying idea and runtime. It was fairly straightforward to reimplement a similar runtime for MPS
2020.3. I didn&rsquo;t bother with any language extensions yet but I could make it work with ScopeProviders.</p>
<p>After using the scope cache in my project the time of scope checks was reduced from several minutes to several seconds.</p>
<p>I have published the scope cache as a library on <a href="https://github.com/specificlanguages/scope-cache">GitHub</a> with
documentation in the README file and pre-built packages available from <a href="https://github.com/orgs/specificlanguages/packages?repo_name=scope-cache">GitHub
Packages</a> and
<a href="https://jitpack.io/#com.spclngs/scope-cache">JitPack</a>.</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
