Philosophy - add-ons/plugin.video.vrt.nu GitHub Wiki

Development philosophy

Over time we learned a thing or two when working on this project.

Most of the following are common sense, however for Kodi plugin projects this is less common than expected.

  1. Unit and integration testing brings reliability

    • And we want to offer a reliable VRT NU experience to our end-users
  2. Drop as many external libraries as possible

    • On slower platforms, importing fancy new libraries like urllib3 or requests takes too long
  3. Import only what is needed, when it is needed

    • Global blanket imports do not help in offering a fast end-user experience
  4. Work with upstream to improve our offering

    • Some issues/improvements really need to go upstream, even if it takes more time to end up at users
  5. Code readability over cleverness

    • Transparency is key if we want outsiders to help improve this project

Importing libraries on Raspberry Pi

Because this goes against Python's philosophy, here is a rationale for not importing libraries globally.

  • We noticed that on Raspberry Pi our Kodi add-on was very slow to start. This appeared to be caused by importing urllib3 (via Requests) and at some point was causing a 4 second delay due to precompiling regular expressions on import. (This was later somewhat improved, but we decided to stick with urllib/urllib2 anyway)

  • During profiling our code we noticed that importing some other libraries was unexpectedly slow, adding more than 1 second to the startup time. And since the design of Kodi add-ons, the add-on is being started for every action. (We implemented reuselanguageinvoker to help here as well)

So these are the import-times for various libraries on a Raspberry Pi 3. These are approximations.

  • routing: 100ms (globally)
  • urllib: 100ms (most codepaths)
  • urllib2: 120ms (most codepaths)
  • dateutil: 40ms (when needed)
    • six: 40ms (indirectly used, via dateutil)
  • beautifulsoup4: 100ms (when needed)
  • pysocks: 130ms (optionally, when needed)
  • requests: 1100ms (no longer used)
    • urllib3: 900ms
    • chardet: 70ms
    • certifi: 20ms
    • idna: 50ms
  • inputstreamhelper: (when used)
    • kodi-six: 50ms (no longer used)

This is on top of importing the standard Kodi libraries. For this reason we decided to not load all required Python libraries by default, but only import the libraries we need in the code-path that needs it. We do this not just for external libraries, we do the same for our own libraries where it makes sense.

For libraries that are needed everywhere (like routing) we do import them globally.

We brought startup import times down from a 1.5sec to 250ms in most cases on Raspberry Pi. Comparing our add-on startup time compared to other add-ons this is very noticable.