Introduction

I have noticed an interesting anomaly between Pyodide and Pyscript. Pyscript takes about one second longer to load an HTML + Python page than Pyodide. Pyodide averages 2 seconds and Pyscript 3 seconds.

Other interesting stats:

Downloads:

  • Pyodide downloads 8.0 MB compressed – 18.0 MB uncompressed
  • Pyscript downloads 8.7 MB compressed – 22.7 MB uncompressed.

Load Times:

  • Pyodide loads in 558 ms on average and finishes in 2 seconds on average.
  • Pyscript loads in 2900 ms on average and finishes in 3 seconds on average.

Pyscript load seven additional files:

  • pyscript.js
  • pyscript.css
  • livereload.js
  • packages.json
  • micropip-0.1-py3-none-any.whl
  • pyparsing-3.0.7-py3-none-any.whl
  • packaging-21.3-py3-none-any.whl

The file packages.json lists the supported Python packages. Knowing the content of this file is important.

One item I discovered from packages.json is that Pyscript/Pyodide is WASM32 (32-bit) and not WASM64. This will be an important item for AI/ML/Data Science as WASM32 in the browser might only support 2 GB of memory. I need to test this as there is work being done in Chrome to support 4 GB of memory link. I had incorrectly assumed that 32-bit anything was no longer being designed for new architectures.

Demo Examples

Start your browser, enable the debugger, go to the Network tab, and load these pages. These pages will show the page load times for Pyodide and Pyscript.

Notice the delay that happens on the second link during the load of distutils.tar. There is something delaying that step. I do not know why yet. The key is that Pyodide is faster than Pyscript. However, Pyscript is offering additional features.

I am including the code for these examples.

Pyodide Page Load Time Example:

This example also demonstrates how to call a Python function from JavaScript and how to access a JavaScript variable from Python.

Pyscript Page Load Time Example:

Summary

Currently, Pyscript is in alpha status and Pyodide is at version 0.20. That means neither one is production. My objective in analyzing the page start times is to find ways to improve this. One technique I am reviewing is the Virtual File System. By switching the file system to IDBFS, which is backed by IndexedDB, Pyscript and Pyodide files can be saved for faster page loading for the same domain. I will publish another article on the Virtual File System.

More Information

Photography Credit

I write free articles about technology. Recently, I learned about Pexels.com which provides free images. The image in this article is courtesy of Pixabay at Pexels.