1702 Commits

Author SHA1 Message Date
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
Mitchell Hashimoto
1a7b9f7465 termio: clear selection 2022-11-05 19:31:02 -07:00
Mitchell Hashimoto
f1d2df1a54 fully hook up resize 2022-11-05 19:31:02 -07:00
Mitchell Hashimoto
b100406a6e termio: start the thread mailbox, hook up resize 2022-11-05 19:31:02 -07:00
Mitchell Hashimoto
a8e7c52041 IO thread can trigger render and write data 2022-11-05 19:31:02 -07:00
Mitchell Hashimoto
d916d56bff IO thread stream handler is in, lots of commented TODOs 2022-11-05 19:31:02 -07:00
Mitchell Hashimoto
9b3d22e55e IO thread has more state setup 2022-11-05 19:31:02 -07:00
Mitchell Hashimoto
35c1decd58 Start pulling out IO thread and IO implementation 2022-11-05 19:31:02 -07:00
Mitchell Hashimoto
8dd67662b3 Blocking queue implementation for thread message passing 2022-11-05 19:31:02 -07:00
Mitchell Hashimoto
72ac3b4685 re-enable hot path optimization 2022-11-03 15:37:24 -07:00
Mitchell Hashimoto
d75e869b4e Load $XDG_CONFIG_HOME/ghostty/config if it exists (#25)
Ghostty now loads the config file in `$XDG_CONFIG_HOME/ghostty/config` if it exists on startup. This follows the XDG base dir specification so if $XDG_CONFIG_HOME is not set, we default to `$HOME/.config/ghostty/config`.
2022-11-02 16:12:50 -07:00
Mitchell Hashimoto
116a157e17 change defaults to be more aesthetically pleasing 2022-11-01 18:25:36 -07:00
Mitchell Hashimoto
b528d435fb properly handle "inherit" working directory value 2022-11-01 18:22:33 -07:00
Mitchell Hashimoto
df50aacff1 macos: Default working directory to home dir if launched from app
This also introduces a `--working-directory` config flag.
2022-11-01 18:10:30 -07:00
Mitchell Hashimoto
63fab367fe Command supports setting cwd 2022-11-01 17:51:50 -07:00
Mitchell Hashimoto
be1fa78511 extract passwd to its own file so its easier to test 2022-11-01 17:47:34 -07:00
Mitchell Hashimoto
c7db5b96d6 get rid of stage1 compat 2022-11-01 14:10:35 -07:00
Mitchell Hashimoto
74d8d6cd6c source default shell from SHELL if set 2022-11-01 14:09:40 -07:00
Mitchell Hashimoto
7da18d8063 look up default shell in user passwd entry 2022-11-01 14:02:10 -07:00
Mitchell Hashimoto
4d13f2648a update zig 2022-11-01 13:26:46 -07:00
Mitchell Hashimoto
f09ba38c6f remove stage1 hack 2022-11-01 13:25:20 -07:00
Mitchell Hashimoto
3d5ea05565 update zig 2022-10-31 21:34:36 -07:00
Mitchell Hashimoto
9e3bbc1598 macos: send logs to unified logging 2022-10-31 15:16:29 -07:00
Mitchell Hashimoto
7608d7921f pkg/macos: OS Log support 2022-10-31 14:47:10 -07:00
Mitchell Hashimoto
e0933ed62e Update README.md 2022-10-31 14:05:53 -07:00
Mitchell Hashimoto
9d736985b3 Mac bundle, icons 2022-10-31 14:04:41 -07:00
Mitchell Hashimoto
a9df393580 fix mouse scroll direction 2022-10-31 12:09:34 -07:00
Mitchell Hashimoto
a14871e38a Metal Renderer
This implements a pure Metal renderer for macOS targets. 

Performance:
  - Average frame time: 0.7ms (Metal) vs. 1.5ms (OpenGL)
  - Average fps while `cat`-ing a 1GB file (vsync disabled): 100 (Metal) vs. 70 (OpenGL)
    * Note: while the frame time is 2x faster in Metal, the FPS is not 2x for what I assume to be lock contention on terminal state.

Why?
  - OpenGL has been deprecated on macOS since 2018. 
  - All OpenGL has to go through a Metal translation layer anyways, which has a non-zero cost. 
  - There is a bug on Mac where rendering OpenGL on a separate thread from the windowing thread can cause crashes, so most OpenGL software just don't multi-thread render on Mac. 
  - Metal is more explicit about resource management compared to OpenGL, so we gain performance.
  - Metal is much more multi-thread friendly, so our multi-threaded renderer works great! (with resizes!)
2022-10-31 10:48:53 -07:00
Mitchell Hashimoto
8dd68ea5fe metal: reallocate textures if they grow 2022-10-31 10:42:27 -07:00
Mitchell Hashimoto
9e628635c2 metal: hollow rect cursor works 2022-10-31 10:33:31 -07:00
Mitchell Hashimoto
20adaa7b66 metal: disable v-sync 2022-10-31 10:25:49 -07:00
Mitchell Hashimoto
1d1f161b03 metal: fix double wide cell width 2022-10-31 09:44:37 -07:00