Skip to content

Thoughts

theRealProHacker edited this page Feb 22, 2023 · 2 revisions

How can Positron be fast with Python?

  1. Most of the work is done in C: IO, graphics, and calculations
  2. Asynchronous programming

General Style Guide

  1. There is a conflict between confirmacy to the Web Standards and practicality.
    1. We try to implement everything as close to the standards as possible,
    2. But we don't implement deprecated features or features that are not implemented by most mainstream browsers.
    3. If the standards are ridiculous in some aspects, we go our own way, unless someone finds a good reason not to.
    4. We don't implement JavaScript, and we don't need to feel forced to even follow the standards for JavaScript when implementing Python APIs. However, it might still help to look at the JS standards for inspiration.
  2. In GUI Applications its all about what the user feels. It doesn't matter if your code takes 10 seconds to run, unless the user feels it. If you run that code synchronously and the application freezes for 10 seconds, the user will feel it. If you run it asynchronously, and put in a loading sign the user will still see that it takes some time, but he won't care because he expects that things need time to load. Please use async!

Async

To achieve asynchronous code you need two methods:

  1. asyncio.to_thread two turn a synchronous function into an asynchronous one
  2. util.create_task to "fire and forget" a coroutine. You can make it sync which just means that before the page loads the task will definitely have finished. Also you can add an onfinished callback.

Ideas