1033 Commits

Author SHA1 Message Date
Mitchell Hashimoto
333ff1e634 opengl: handle screen resize outside of critical area 2022-11-13 16:19:38 -08:00
Mitchell Hashimoto
f1c69343d3 opengl: copy screen data instead of sharing state
Through benchmarking I've determined this lowers lock contention by
about 50% on the critical data.
2022-11-13 16:16:08 -08:00
Mitchell Hashimoto
81fbc94b3c Add a benchmark exe for testing parser throughput 2022-11-13 11:29:05 -08:00
Mitchell Hashimoto
445ca8998f cli args without arena 2022-11-13 11:21:12 -08:00
Mitchell Hashimoto
3e92ec5ccd update zig 2022-11-09 17:42:33 -08:00
Mitchell Hashimoto
ce85d9a2cd add more tracing, unroll a loop 2022-11-08 19:15:14 -08:00
Mitchell Hashimoto
d1718e6cbf use libc memcpy/memmove instead of std.mem if available 2022-11-08 19:01:45 -08:00
Mitchell Hashimoto
a471eaf980 drop a couple function calls and optimize scrolling a bit 2022-11-08 18:35:19 -08:00
Mitchell Hashimoto
306ab947e7 implement region scrolling directly in screen to use memcpy
This doubles scroll region scrolling speed.
2022-11-08 17:35:15 -08:00
Mitchell Hashimoto
4b2f2a81db update TODO 2022-11-08 14:01:47 -08:00
Mitchell Hashimoto
8a871e1294 missing trace 2022-11-08 13:57:12 -08:00
Mitchell Hashimoto
c1a9184ebd sgr: parse italic (render not implemented) 2022-11-07 14:04:40 -08:00
Mitchell Hashimoto
73c4395fc2 add more traces 2022-11-07 07:59:47 -08:00
Mitchell Hashimoto
5b52333e51 name threads and add more tracing 2022-11-07 07:45:46 -08:00
Mitchell Hashimoto
46a9998762 tracy: support naming threads 2022-11-07 07:33:36 -08:00
Mitchell Hashimoto
7b94153458 libuv: Prepare handles 2022-11-07 07:33:29 -08:00
Mitchell Hashimoto
9ee5a5c715 implement ESC c -- full reset 2022-11-06 18:59:17 -08:00
Mitchell Hashimoto
e7c5cbf758 throttle cursor reset, under heavy IO this would slow things down 2022-11-06 18:44:35 -08:00
Mitchell Hashimoto
f6a3840c5b update zig 2022-11-06 17:44:21 -08:00
Mitchell Hashimoto
25f2c27e4b update TODO 2022-11-06 17:41:27 -08:00
Mitchell Hashimoto
62a3419e81 Multi-Window
This adds the ability to have multiple windows by introducing new keybind actions `new_window`, `close_window`, and `quit`. These are bound on macOS by default to the standard `cmd+n`, `cmd+w`, and `cmd+q`, respectively.

The multi-window logic is absolutely minimal: we don't do any GPU data sharing between windows, so each window recreates a full font texture for example. We can continue to further optimize this in the future.

DevMode is also pretty limited (arguably broken) with multi-window: DevMode only works on the _first_ window opened. If you close the first window, DevMode is no longer available. This is due to complexities around multi-threading and imgui. It is possible to fix this but I deferred it since it was a bit of a mess!
2022-11-06 17:31:19 -08:00
Mitchell Hashimoto
c602820dc9 Set proper keybinds 2022-11-06 17:27:17 -08:00
Mitchell Hashimoto
fd304c9338 Deinit devmode more cleanly 2022-11-06 17:26:01 -08:00
Mitchell Hashimoto
135b859b8f raise max file descriptors on launch 2022-11-06 16:38:33 -08:00
Mitchell Hashimoto
e0db46ac97 clean up some resources better on error 2022-11-06 16:23:36 -08:00
Mitchell Hashimoto
05cd77e7cf DevMode only renders on first window 2022-11-06 16:06:34 -08:00
Mitchell Hashimoto
afd4800da4 pkg/imgui: support context current 2022-11-06 16:03:03 -08:00
Mitchell Hashimoto
705772ed28 termio: clean up error handling for kill 2022-11-06 15:26:18 -08:00
Mitchell Hashimoto
c9b01fdc6c support app quitting to close all windows 2022-11-06 14:10:28 -08:00
Mitchell Hashimoto
ac6f960b92 termio: on deinit, send SIGHUP to child process to exit it 2022-11-06 14:08:42 -08:00
Mitchell Hashimoto
be76bc6c1a close window action 2022-11-06 10:44:23 -08:00
Mitchell Hashimoto
410b2b4486 Do not block on app mailbox 2022-11-06 10:41:57 -08:00
Mitchell Hashimoto
ecbd119654 Hook up new window, modify renderers 2022-11-06 10:34:43 -08:00
Mitchell Hashimoto
a2edbb4698 App prepare for multi-window 2022-11-06 10:05:08 -08:00
Mitchell Hashimoto
91d165f4f9 delete unused comment 2022-11-06 09:41:59 -08:00
Mitchell Hashimoto
0104032679 Move pty IO to dedicated thread
* This completes ours multi-threaded architecture started with #21 by moving pty IO to a dedicated thread.
* A bounded, blocking queue implementation is introduced for inter-thread communication.
* The Window thread (which previously also did IO) no longer uses libuv, and is purely a windowing event loop.

## Performance

On IO heavy workloads such as `cat big-file.txt`, throughput has increased by more than 400%. In general, I'm noticing more consistent frame rates across all workloads, with dramatic differences in IO heavy workloads.

## Architectural Notes

There are now three threads per window as shown below:

```
                    ┌─────────────────────────────────┐
                    │                                 │
                    │             Window              │
                    │                                 │
                    └─────────────────────────────────┘
                                     │
                 ┌───────────────────┴──────────────────┐
                 │                                      │
                 ▼                                      ▼
┌─────────────────────────────────┐    ┌─────────────────────────────────┐
│                                 │    │                                 │
│            Renderer             │◀───│               IO                │
│                                 │    │                                 │
└─────────────────────────────────┘    └─────────────────────────────────┘
```

Notes:

* The window thread is responsible purely for windowing events: focus, mouse movement, keyboard input, etc.
* The IO thread is responsible for pty IO such as reading and writing to the pty fd. This thread also owns the terminal state.
* The renderer is responsible for turning terminal state into screen data, and auxiliary visual functions such as cursor blink.

The arrows in the diagram above show how threads can communicate. Communication is done through one-way, MPSC (multi-producer single-consumer) bounded queues. The MPSC queue implementation is _not optimal_ and can be improved but our workload is not a message-heavy workload.

Threads _also use shared memory_, as noted in #21. For large data structures such as terminal state, mutexes are utilized to avoid large copies.
2022-11-05 19:44:13 -07:00
Mitchell Hashimoto
8f1fcc64e8 rename termio thread message struct 2022-11-05 19:34:41 -07:00
Mitchell Hashimoto
cd705359e8 Window thread is now single event loop! 2022-11-05 19:31:28 -07:00
Mitchell Hashimoto
746858cea6 implement cursor reset when data comes in pty 2022-11-05 19:31:28 -07:00
Mitchell Hashimoto
aa98e3ca3a Move cursor timer to renderer 2022-11-05 19:31:28 -07:00
Mitchell Hashimoto
e2d8ffc3c1 renderer mailbox, focus message 2022-11-05 19:31:28 -07:00
Mitchell Hashimoto
9a44e45785 bug: assume focused on launch 2022-11-05 19:31:28 -07:00
Mitchell Hashimoto
95d054b185 allocate data for paste data if its too large 2022-11-05 19:31:28 -07:00
Mitchell Hashimoto
8652b2170e fix deadlock with mouse reports 2022-11-05 19:31:28 -07:00
Mitchell Hashimoto
90061016df field rename 2022-11-05 19:31:28 -07:00
Mitchell Hashimoto
a05b08fdc7 move bracketed paste to terminal state 2022-11-05 19:31:28 -07:00
Mitchell Hashimoto
57b4c73bb2 remove unused fields on Window 2022-11-05 19:31:28 -07:00
Mitchell Hashimoto
f2d9475d5d Switch over to the IO thread. A messy commit! 2022-11-05 19:31:26 -07:00
Mitchell Hashimoto
5cb6ebe34d Actually, we'll manage selection and viewports on the windowing thread 2022-11-05 19:31:02 -07:00
Mitchell Hashimoto
989046a06c More IO events 2022-11-05 19:31:02 -07:00