<feed xmlns='http://www.w3.org/2005/Atom'>
<title>mirrors/foot.git/grid.c, branch 1.10.1</title>
<subtitle>A fast, lightweight and minimalistic Wayland terminal emulator</subtitle>
<id>https://git.0x0f.dev/mirrors/foot.git/atom?h=1.10.1</id>
<link rel='self' href='https://git.0x0f.dev/mirrors/foot.git/atom?h=1.10.1'/>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/'/>
<updated>2021-11-21T17:09:27Z</updated>
<entry>
<title>grid: refactor grid_row_uri_range_erase()</title>
<updated>2021-11-21T17:09:27Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-11-20T14:46:20Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=f27ccd999ef6fcf10f99aed9f6aec449fe071551'/>
<id>urn:sha1:f27ccd999ef6fcf10f99aed9f6aec449fe071551</id>
<content type='text'>
The old algorithm always created a new URI, followed by (maybe)
removing the existing URI, when an URI needed to be modified.

That is, if e.g. the tail of an URI was being erased, the old
algorithm would create a new URI for the part of the URI that should
remain, and then removed the old URI.

This isn’t very effective. The new algorithm instead identifies all
possible overlap cases, and handles each one differently:

* URI ends *before* erase range starts - continue with the next URI
  without further checks
* URI starts *after* the erase range ends - return, we’re done
* Erase range erases the entire URI - remove the URI
* Erase range erases a part in the middle - split the URI
* Erase range erases the head of the URI - adjust the URI’s start
* Erase range erases the tail of the URI - adjust the URI’s end
</content>
</entry>
<entry>
<title>grid: row_uri_range_erase(): assume caller has checked row-&gt;extra != NULL</title>
<updated>2021-11-21T17:09:27Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-11-20T13:40:16Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=503c2ebd50caaf1d50b57c42d319973277a583e0'/>
<id>urn:sha1:503c2ebd50caaf1d50b57c42d319973277a583e0</id>
<content type='text'>
</content>
</entry>
<entry>
<title>grid: add grid_row_uri_range_erase()</title>
<updated>2021-11-21T17:09:26Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-11-20T12:42:07Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=1a0de0017f7b2061bad0b695a98963ca0f274e21'/>
<id>urn:sha1:1a0de0017f7b2061bad0b695a98963ca0f274e21</id>
<content type='text'>
This function handles erasing of an URI range. That is, a range of the
row is being either erased, or overwritten (from the URI perspective,
these two are the same thing).

We handle both partial overwrites (split up, or truncate URI), as well
as complete overwrites (remove URI).
</content>
</entry>
<entry>
<title>composed: store compose chains in a binary search tree</title>
<updated>2021-06-24T15:30:49Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-24T11:17:07Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=fe8ca23cfee77a6cac433892755dd7455e354a9d'/>
<id>urn:sha1:fe8ca23cfee77a6cac433892755dd7455e354a9d</id>
<content type='text'>
The previous implementation stored compose chains in a dynamically
allocated array. Adding a chain was easy: resize the array and append
the new chain at the end. Looking up a compose chain given a compose
chain key/index was also easy: just index into the array.

However, searching for a pre-existing chain given a codepoint sequence
was very slow. Since the array wasn’t sorted, we typically had to scan
through the entire array, just to realize that there is no
pre-existing chain, and that we need to add a new one.

Since this happens for *each* codepoint in a grapheme cluster, things
quickly became really slow.

Things were ok:ish as long as the compose chain struct was small, as
that made it possible to hold all the chains in the cache. Once the
number of chains reached a certain point, or when we were forced to
bump maximum number of allowed codepoints in a chain, we started
thrashing the cache and things got much much worse.

So what can we do?

We can’t sort the array, because

a) that would invalidate all existing chain keys in the grid (and
iterating the entire scrollback and updating compose keys is *not* an
option).

b) inserting a chain becomes slow as we need to first find _where_ to
insert it, and then memmove() the rest of the array.

This patch uses a binary search tree to store the chains instead of a
simple array.

The tree is sorted on a “key”, which is the XOR of all codepoints,
truncated to the CELL_COMB_CHARS_HI-CELL_COMB_CHARS_LO range.

The grid now stores CELL_COMB_CHARS_LO+key, instead of
CELL_COMB_CHARS_LO+index.

Since the key is truncated, collisions may occur. This is handled by
incrementing the key by 1.

Lookup is of course slower than before, O(log n) instead of
O(1).

Insertion is slightly slower as well: technically it’s O(log n)
instead of O(1). However, we also need to take into account the
re-allocating the array will occasionally force a full copy of the
array when it cannot simply be growed.

But finding a pre-existing chain is now *much* faster: O(log n)
instead of O(n). In most cases, the first lookup will either
succeed (return a true match), or fail (return NULL). However, since
key collisions are possible, it may also return false matches. This
means we need to verify the contents of the chain before deciding to
use it instead of inserting a new chain. But remember that this
comparison was being done for each and every chain in the previous
implementation.

With lookups being much faster, and in particular, no longer requiring
us to check the chain contents for every singlec chain, we can now use
a dynamically allocated ‘chars’ array in the chain. This was
previously a hardcoded array of 10 chars.

Using a dynamic allocated array means looking in the array is slower,
since we now need two loads: one to load the pointer, and a second to
load _from_ the pointer.

As a result, the base size of a compose chain (i.e. an “empty” chain)
has now been reduced from 48 bytes to 32. A chain with two codepoints
is 40 bytes. This means we have up to 4 codepoints while still using
less, or the same amount, of memory as before.

Furthermore, the Unicode random test (i.e. write random “unicode”
chars) is now **faster** than current master (i.e. before text-shaping
support was added), **with** test-shaping enabled. With text-shaping
disabled, we’re _even_ faster.
</content>
</entry>
<entry>
<title>grid: reflow: ‘amount’ has already been added to ‘from’</title>
<updated>2021-06-02T18:13:52Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-02T17:30:01Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=3292bb5b8eaddb8a0354387fcc2d8f9ffd0d1ac4'/>
<id>urn:sha1:3292bb5b8eaddb8a0354387fcc2d8f9ffd0d1ac4</id>
<content type='text'>
</content>
</entry>
<entry>
<title>grid: reflow: URI range start: take over ownership of URI string</title>
<updated>2021-06-02T18:13:52Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-28T16:19:21Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=a003e56fdc2300818760bcdf020219604bb285ab'/>
<id>urn:sha1:a003e56fdc2300818760bcdf020219604bb285ab</id>
<content type='text'>
Instead of strdup:ing the URI, take over ownership. This is ok since
the old URI range will be free:d anyway.
</content>
</entry>
<entry>
<title>grid: reflow: debug logging</title>
<updated>2021-06-02T18:13:51Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-28T15:42:25Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=8a9643de67458e1958839e994350621e4588808f'/>
<id>urn:sha1:8a9643de67458e1958839e994350621e4588808f</id>
<content type='text'>
</content>
</entry>
<entry>
<title>grid: reflow: when determining row end coord, check *last* URI range</title>
<updated>2021-06-02T18:13:51Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-28T15:42:09Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=ceab9b93675f523f25b1eea410cd42d408d8c020'/>
<id>urn:sha1:ceab9b93675f523f25b1eea410cd42d408d8c020</id>
<content type='text'>
</content>
</entry>
<entry>
<title>grid: reflow: when determining row end coord, check *last* tracking point</title>
<updated>2021-06-02T18:13:51Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-28T15:41:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=5a08ed641b39fcd84373ac120ecfb2d11f9987b9'/>
<id>urn:sha1:5a08ed641b39fcd84373ac120ecfb2d11f9987b9</id>
<content type='text'>
</content>
</entry>
<entry>
<title>grid: reflow: check the *entire* row for non-empty cells</title>
<updated>2021-06-02T18:13:51Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-28T15:41:13Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=ef1fdc40c8fd10411e7c40e0fe0d6982a702f505'/>
<id>urn:sha1:ef1fdc40c8fd10411e7c40e0fe0d6982a702f505</id>
<content type='text'>
</content>
</entry>
<entry>
<title>grid: reflow: avoid unnecessary if-statements before chunking a row</title>
<updated>2021-06-02T18:13:51Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-26T10:27:12Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=c2314d689e9e36dc4e104051e2c2b15d0e71d99b'/>
<id>urn:sha1:c2314d689e9e36dc4e104051e2c2b15d0e71d99b</id>
<content type='text'>
</content>
</entry>
<entry>
<title>grid: disable reflow timing by default</title>
<updated>2021-06-02T18:13:51Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-26T10:22:28Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=2029d201b571753585f5df1b0f7265adfca722a5'/>
<id>urn:sha1:2029d201b571753585f5df1b0f7265adfca722a5</id>
<content type='text'>
</content>
</entry>
<entry>
<title>grid: reflow: comments</title>
<updated>2021-06-02T18:13:51Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-25T17:40:10Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=ac97f20f997e300f87cb4c38ace331e529168d66'/>
<id>urn:sha1:ac97f20f997e300f87cb4c38ace331e529168d66</id>
<content type='text'>
</content>
</entry>
<entry>
<title>grid: no need to keep the tp_col/uri_col variables around</title>
<updated>2021-06-02T18:13:51Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-25T17:34:21Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=5325ea042decae3d44d1cba54abb782a6fcd532c'/>
<id>urn:sha1:5325ea042decae3d44d1cba54abb782a6fcd532c</id>
<content type='text'>
</content>
</entry>
<entry>
<title>grid: fix col max calculation when row contains URI ranges</title>
<updated>2021-06-02T18:13:51Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-25T17:32:25Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=3453f091a3349e6a977d69e07c1be6d3fe39c939'/>
<id>urn:sha1:3453f091a3349e6a977d69e07c1be6d3fe39c939</id>
<content type='text'>
</content>
</entry>
<entry>
<title>grid: set tp/uri break flags explicitly when we know them to be true</title>
<updated>2021-06-02T18:13:51Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-25T17:31:38Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=a56b54ad2f3cc0f5d43a1f32227d4f3867c07867'/>
<id>urn:sha1:a56b54ad2f3cc0f5d43a1f32227d4f3867c07867</id>
<content type='text'>
</content>
</entry>
<entry>
<title>grid: reflow: slightly simplified logic for end-coordinate calculation</title>
<updated>2021-06-02T18:13:51Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-25T17:28:11Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=4b7e4fb885a3d9aa7fa2152ee9439964a420ea20'/>
<id>urn:sha1:4b7e4fb885a3d9aa7fa2152ee9439964a420ea20</id>
<content type='text'>
</content>
</entry>
<entry>
<title>grid: reflow: rename _range -&gt; range</title>
<updated>2021-06-02T18:13:51Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-25T17:22:52Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=315865f18ca5b12dbf93ee4cdebd1b4116dadd1d'/>
<id>urn:sha1:315865f18ca5b12dbf93ee4cdebd1b4116dadd1d</id>
<content type='text'>
</content>
</entry>
<entry>
<title>grid: reflow: remove dead code</title>
<updated>2021-06-02T18:13:50Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-25T17:20:25Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=7c3a4b24d9358a65331a5c4e8b134e8df637ccdf'/>
<id>urn:sha1:7c3a4b24d9358a65331a5c4e8b134e8df637ccdf</id>
<content type='text'>
</content>
</entry>
<entry>
<title>grid: reflow: memcpy() chunks of cells, instead of single cell-by-cell</title>
<updated>2021-06-02T18:13:50Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-23T19:15:06Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=40ca86b2d30873ac13c73360a777cfa40b705a7e'/>
<id>urn:sha1:40ca86b2d30873ac13c73360a777cfa40b705a7e</id>
<content type='text'>
Instead of walking the old grid cell-by-cell, and checking for
tracking points, OSC-8 URIs etc on each cell, memcpy() sequences of
cells.

For each row, find the end column, by scanning backward, looking for
the first non-empty cell.

Chunk the row based on tracking point coordinates. If there aren’t any
tracking coordinates, or OSC-8 URIs on the current row, the entire row
is copied in one go.

The chunk of cells is copied to the new grid. We may have to split it
up into multiple copies, since not all cells may fit on the current
“new” row.

Care must also be taken to not line break in the middle of a
multi-column character.
</content>
</entry>
</feed>
