<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="224174" data-post-id="224174">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="qhwa" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/qhwa/120/17564_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  qhwa
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m glad to see it is helpful to you too! And I really appreciate that you give it a try.</p>
<p>Please be aware that, as discussed here, Formular is not a safe sandbox right now. The design purpose is more about <em>compiling your configuration</em> into runnable code inside the application. So if the code comes from some untrusted user inputs, it could potentially damage the system. Improving is on the way though.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="224174" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/formular-a-tiny-dsl-engine-code-evaluator-configuration-as-code/41916/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-224174" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="224174"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="224273" data-post-id="224273">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="collegeimprovements" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/collegeimprovements/120/271_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  collegeimprovements
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I don’t get code from user input.<br>
So safety is sorted for us.</p>
<p>The big benefit with Formular for us is that since it’s easy to understand, business can modify the rules.<br>
And that way we can keep the logic as Formular rules and away from the codebase.</p>
<p>Thanks a lot for Formular.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="224273" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/formular-a-tiny-dsl-engine-code-evaluator-configuration-as-code/41916/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-224273" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="224273"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="228313" data-post-id="228313">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="qhwa" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/qhwa/120/17564_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  qhwa
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Two new versions have been released:</p>
<ul>
<li>
<p><strong>v0.2.2</strong></p>
<ul>
<li>brings performance improvements to <code>0.2.x</code></li>
</ul>
</li>
<li>
<p><strong>v0.3.0</strong></p>
<ul>
<li>allows limiting the execution time and heap size</li>
<li>allows compiling a code string to an Elixir module which brings more performance improvements,</li>
<li>adds new API <code>Formula.used_vars/2</code> to extract the used variable names in the formula.</li>
</ul>
</li>
</ul>
<p>Highlights:</p>
<p><strong>Performance improvements:</strong></p>
<p><a href="https://github.com/qhwa/formular/blob/master/benchmark.exs" rel="noopener nofollow ugc">A simple benchmark</a> on a simple formula results in this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Name                      ips        average  deviation         median         99th %
compiled_module      947.84 K        1.06 μs  ±5536.01%        0.83 μs        1.45 μs
eval                  14.53 K       68.82 μs     ±8.93%       68.69 μs       87.93 μs
eval_ast               4.86 K      205.58 μs    ±18.43%      193.89 μs      333.89 μs

Comparison: 
compiled_module      947.84 K
eval                  14.53 K - 65.23x slower +67.76 μs
eval_ast               4.86 K - 194.85x slower +204.52 μs
</code></pre>
<p>The compilation approach is about 80x faster than the original eval approach in v0.2.2, and 300x faster than versions prior to v0.2.2.</p>
<p><strong>Restricted evaluation:</strong></p>
<ul>
<li>
<p>limited execution time:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Formular.eval(code, timeout: :timer.seconds(5))
</code></pre>
</li>
<li>
<p>limited max heap size by word:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Formular.eval(code, max_heap_size: 15_000)
</code></pre>
</li>
</ul>
<p>If limited, the evaluation will be run in a separate process.</p>
<p><strong>Extract used vars API:</strong></p>
<p>This can be helpful if you need to build some UI arround the formula.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex&gt; Formular.used_vars("a + b - 1")
[:a, :b]
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="228313" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/formular-a-tiny-dsl-engine-code-evaluator-configuration-as-code/41916/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-228313" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="228313"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>