Learn

Contents

Inside eLucid8: how it runs, and how fast

Who this page is for: anyone who wants to know what happens inside elucid8 when a program runs, how its speed and memory are measured, and where it can get faster. To use eLucid8, the Tutorial and How eLucid8 fits together are the places to start.

An eLucid8 program is a set of equations that define values over named dimensions. Its meaning is fixed by the equations alone: the answer at any point is what the equations say it is. Everything on this page is how the implementation finds that answer quickly and in little memory. None of it is allowed to change an answer: caches, compiled loops, the number of threads, and how much memory is kept decide only how fast an answer comes and how much memory it takes.

The pieces

Eduction: computing only what is asked for

At the centre of the engine is eduction, Lucid's demand-driven evaluation. Nothing is computed until a point is asked for. Asking for total[t = 5] starts from that point and follows the equations: total at 5 needs total at 4 and reading at 5, and so on down, and only those points are computed.

Eduction is what lets eLucid8 answer one cell of a large simulation without computing the rest: on the 512 × 512 heat plate, one probe cell at step 100 reads 5% of the field, and is answered 16 times faster than NumPy computes the whole plate (Examples).

Compiled loops (kernels)

Evaluating one point at a time is flexible, but most of its time goes on bookkeeping: a key for each point, a lookup, a place on the stack of demands. Where the equations say in advance what a region of points will read, the engine computes the whole region in compiled loops instead.

For example, with

avg3 = mean reading over (t : #t - 2 .. #t) end

a query for avg3[t = 0..9999] tells the engine, before anything is computed, that it needs reading from t = 0 to 9999. It reads that once into an array and runs one loop, which in outline is

for t in 0..9999:
    avg3[t] = (reading[t-2] + reading[t-1] + reading[t]) / 3

with no key or lookup per point (positions below 0 are left out of the mean, as the language says).

On the heat simulation, computing by levels is about 30 times faster than one point at a time on one thread, and splitting the levels across 18 threads makes it about 8 times faster again.

Where values are kept

When a demand looks for a value, it looks in these places, in order:

  1. Region arrays, computed by loops for a box query.
  2. Levels of an iteration being computed.
  3. The memo: points computed one at a time in this query.
  4. The point cache, if switched on: answers kept from earlier queries.

Then, if none holds it, the point is computed, and the answer goes into the memo.

Arrays are flat. A region is a box (a range of coordinates along each dimension, and every combination of them) laid out as one contiguous block of 64-bit numbers, the last dimension varying fastest, as in NumPy's C order. Beside it are one byte per element saying whether it is a value, exactly eod, or "not known here", and, only when the data carry timestamps, a column of timestamps. Where every timestamp is a simple function of one coordinate (a reading's tick, say), it is kept once per coordinate instead of once per element. Texts are numbered and the array holds their numbers; errors are kept beside the array by element, with the chain that says where they began. There are no nested arrays: every expression denotes one value at each point, so a shift or a neighbourhood is a strided read into another flat array.

The memo is mostly arrays too. Points computed one at a time over whole-number dimensions are kept in blocks of 64 (8 × 8 on a grid), found by arithmetic on the coordinates rather than by hashing a key. Values over texts or real numbers, and points too scattered to fill blocks, are kept in a map by key.

Memory

Within a query, the engine keeps what it computed only while something may still read it:

Peak memory is therefore set mostly by the data read and by one slab or level of work, not by the length of a history.

Across queries, and after corrections

By default each query starts afresh. Keeping answers across queries is a choice, because it costs memory and pays only when the same answers are asked again.

Reading and writing data

Exact numbers, the same everywhere

Answers are the same bits on every engine, every machine and every number of threads. Three things make this so, and each has a cost.

How speed and memory are measured

Each of the examples has a baseline/ folder holding the same computation written as a user of another tool would write it (NumPy; DuckDB SQL; Polars; pandas), checked against eLucid8's answers. Its measure.py runs eLucid8 and each baseline at full size, one after the other.

Results, in brief

The Examples page has every number and what each comparison measures. In brief, with each tool at its defaults:

taskeLucid8against
heat simulation, the whole 512 × 512 plate at step 1,0000.35 s3.8× faster than NumPy
heat simulation, one probe cell at step 1000.017 s16× faster than NumPy (which computes the whole plate)
sensor field, 1,000 ticks from a 1.1 GB CSV1.42 s3.1× faster than NumPy
point-in-time feature table, 36.5 million rows4.14 slevel with DuckDB; 3.5× faster than pandas
every trade of a day priced against its quote6.00 s1.5× faster than DuckDB, 1.7× faster than Polars (pandas not measured: it needs about 40 GB here)

Peak memory: on the sensor field, NumPy 8.3 GB and elucid8 2.5 GB; on the feature table, elucid8 0.7 GB, DuckDB 6.2 GB and pandas 12 GB; on the markets, eLucid8 7.1 GB, DuckDB 18.6 GB and Polars 27.0 GB.

Where eLucid8 is slower today:

How performance could improve

These are the known ways eLucid8 can get faster or leaner, from measurements of the examples and of the engine. None changes an answer.

Computing less

Using the threads better

Faster arithmetic

Moving data

Memory

Larger machines