Need for Speed: Voilà edition
TL;DR: Voilà 0.3.0 is now available!

Voilà turns Jupyter notebooks into standalone applications without requiring any modification to the content. You want to share your content with non-technical readers? Just call Voilà with the notebook to turn it into a deployable web application. The simplicity of Voilà comes at a cost: the page load time.
We set ourselves to fix this Achilles’ heel while preserving the ease-of-use of Voilà. Today we are pleased to announce the release of Voilà 0.3.0, with a focus on performance.
Motivation
Page load time has a critical impact on user experience of a website.
According to Kissmetrics, nearly half of web users expect a site to load in 2 seconds or less, and they tend to abandon a site that is not loaded within 3 seconds.
In the case of Voilà, a simple dashboard takes around one second to render and more complicated dashboards (involving libraries import, data fetching, and widgets) can easily push users out of their comfort zone. Several efforts have been made to improve the situation, from adding an execution progress indicator to enhancing the rendering technique. The load time of a medium-to-high complexity notebook has not been cut down to a desirable range yet. That is why in the 0.3.0 version, we aimed at addressing the main bottleneck of Voilà: the execution of notebook.
Preheated kernels
Based upon an excellent idea of the hotpot_km project about the pooling hot-loaded Jupyter kernels, we implemented a new solution called “preheated kernels” to diminish the waiting time for starting a new python kernel and for executing the requested notebook.
Preheated kernels can be activated just by setting thepreheat_kernel
option to True
in the Voilà command line or configuration file. For example, this command will activate preheated kernels feature for the voila.ipynb
notebook with a pool of five kernels:
voila voila.ipynb --preheat_kernel=True --pool_size=5

Behind the scene, the two following actions are performed:
- For each notebook, a queue of kernels is created and the notebook is executed in every kernel. When a new client requests a kernel, the oldest preheated kernel of the pool is used and another kernel is started asynchronously to refill the pool.
- The rendered HTML for the notebook is produced in advance for each preheated kernel and directly served to the client upon connection.
- If the kernel pool is empty, Voilà will fall back to starting a new kernel and render the notebook as usual. The advanced configurations of preheated kernels are detailed in Voilà’s official documentation.
Partially pre-render notebook
To benefit from the acceleration of preheated kernels mode, the notebooks need to be pre-rendered before users connect to Voilà. But in many real-world applications, the notebook requires user-specific data, which makes pre-rendering impossible. To overcome this limit, Voilà offers a feature to handle the most used method for providing user data: the URL query string.

In normal mode, Voilà users can get the query string at run time through the QUERY_STRING
environment variable:
import os
query_string = os.getenv('QUERY_STRING')
In preheated kernels mode, users can simply replace the os.getenv
call with the helper get_query_string
from voila.utils
from voila.utils import get_query_string
query_string = get_query_string()
get_query_string
will pause the execution of the notebook by the preheated kernel at this cell and wait for an actual user to connect to Voilà, then get_query_string
will return the URL query string and continue the execution of the remaining cells.
To maximize the benefits of preheated kernels, the user-independent cells should be placed before the get_query_string
call.
What’s next?
There is more in the works to improve Voilà’s performances. Beyond kernel hot pooling, we will improve the performance of rendering Jupyter widgets in the front-end. Several of these improvements will be enabled with the upcoming 8.0 release of ipywidgets, and more optimizations are in the works.
Acknowledgments
We would like to thank Vidar Tonaas Fauske and Maarten Breddels for the prior art on the hotpot_km project, which was an inspiration for this work in core Voilà.
About the author
Duc Trung Le is a Scientific Software Developer at QuantStack. He works on several projects within the Jupyter ecosystem, from the main projects like JupyterLab, Voilà, ipywidgets to Jupyter extensions and widgets.