Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's the 512b magic number? #62

Closed
osdevisnot opened this issue Nov 22, 2019 · 2 comments
Closed

What's the 512b magic number? #62

osdevisnot opened this issue Nov 22, 2019 · 2 comments

Comments

@osdevisnot
Copy link

This is mostly a question, but I was wondering what's so special about 512b number? Looking at some of the open/closed issues it seems you are attempting to fit an entire website (lib + css + app) in the MTU size (usually 1500 bytes). But I have no idea about iot devices, and I'm trying to figure implications of exceeding 1500 bytes.

Any pointers that can help me wrapping my head around the size limitations?

@wavesoft
Copy link
Owner

wavesoft commented Nov 25, 2019

Hello @osdevisnot !

Yes this indeed a magic number... but it's purpose is two-fold:

1. It just as small as it has to be

First of all, start by having a look on the specs of an average device that could be used for IoT. For example to the ARDUINO MKR1000 WIFI. You will notice on the tech specs that it says:

Flash Memory | 256 KB

Most of the MCUs in the market don't have a much bigger flash size, and don't forget that this size includes the bootloader, C/C++ libraries, a web server and your business logic in addition to the static files for the static UI you want to serve.

This means that you should optimise things as much as physically possible. Ideally, your entire UI must fit in less than a KB!

With this in mind, I started sketching out possible implementations of the library and aimed to fit it in the smallest power of 2 that I could reach. Interestingly enough, in around 400-500 bytes (Gzipped) I managed to squeeze all of the logic that could satisfy my demands.

So the closest power of 2 was 512 bytes, giving me some slack for future features.

2. It is a contract

After setting on that number, I decided to make this a contract, and lock this library to it. Even though it sounds controversial, this has quite some benefits:

  1. Embedded system designers are very cautious with the size of their solution, and having a library with consistent size is a big plus.

  2. Developing under a size constraint made me pay more attention to the code-base, and made me realise that it's possible to add more features in a code-base without increasing it's size.

  3. So far this the smallest library in the market with this feature-set, and I would like to keep it this way.

However I am still willing to break this contract if there is a powerful feature that the community will desire 😄

@wavesoft
Copy link
Owner

wavesoft commented Nov 25, 2019

Also, the "Fitting into an MTU" exercise was just a demonstration on how small you can really make things.

In a more real-world examples, I have already developed a few user interfaces for such IoT devices using .dom :

  1. A configuration user interface that is mobile-first, responsive and has 15 different widgets.

  2. A javascript code editor with syntax highlight

  3. A log-viewing user interface that can render and live-filter gigabytes of log lines (using virtual viewport)

Each one of these interfaces is about 3.5Kb in size (js, css, html and all other assets included)

@wavesoft wavesoft pinned this issue Nov 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants