May Writeup
Bold is a fast text editor. You can find details on the home page.
This is the second month of the rewrite. The beginning of the month was fine and fairly productive. I wrote tests and began writing code to support multiple windows. The second half of the month was mostly event system and threads.
Event System
I wasn't sure how I wanted events to look so I ignored it until I had code that would use it. For the first few events I implemented something simple, I created an os pipe (pipe/createpipe) and would write 32 bytes to it for each event. The struct I would read into had generic parameter names and I would write the producer and consumer code at the same time. This was fine until I had to change some events. Depending on how big the consumer code is, I could potentially forget that I changed what genericParam1 did on a single line. Worse was if I had an event that was produced at multiple places I may update one (or two) and forget the other. I gave each event a struct which made it go from hard to easy but it immediately became hard again.
The next issue I had was wanting to recommend a group of events be run on the same thread and work stealing. I could have a pipe for each thread, but work stealing would want to steal work at the end of a queue so it's less likely to be part of the group a thread is currently working on. So I switched to a lockless structure and would call sleep/wake on a memory address (look up futex or fast mutex) but that code isn't done yet. I have written a lockless data structure before (I don't recommend it) so it wasn't too bad but at the moment it's a first draft and I want to test it more.
The third problem I ran into is I don't want to block but I can potentially have unlimited events. The first problematic event was scanning the filesystem for a list of files (for the folder and subfolders). Potentially there could be a softlink and a circular dependency which I haven't written code to check for, but the problem is what if there are 10 million files and the folder is over a network. I don't want my UI or background thread (which handles autocomplete and such) to be blocked for minutes because there were lots of files. This situation is perfect for green threads. Instead, I wrote code that could emit 1 or more messages and can check how much space is in the event queue. It wasn't until after I wrote the code that I found myself annoyed at writing and testing it. I might look into green threads if there's more code that might annoy me like this.
File Cache
In the middle of doing the above, I wrote a file cache so if I searched text in a folder I wouldn't need to load them from disk every time. At the moment I read the folder every time but not the file. I know OSes cache files but when I search text I typically do it a lot and I don't really want to read files into memory and throw it away milliseconds later. So far I haven't regretted writing it but we'll see later if it causes any problems. I figure since I'm re-reading the folder again and calling stat on every file I probably won't have corner cases that will backfire. I only cache the actual reading of the file.
I'm looking forward to next month. Maybe I'll actually render and edit a source file. That was the first thing I implemented in the original source, I understand that part of the editor well enough that I can focus on new things first.