Rust Browser 8: Next Steps
At this point I’ve been working on the browser for over a month and I’ve learned a ton about Rust. Sadly, it’s time for me to stop. I’ve taken it about as far as I can.
What I’ve learned
I chose to build a new web browser in Rust as an excercise, with the sole goal of learning Rust. I messed around with Rust a few years ago but haven’t tried it since. Now that I’ve used the modern 2018+ incarnation I can say that it’s a very powerful language that is perfect for certain types of projects. Had I tried to build a browser in C++ I would never have gotten so far. I’d still be fighting segfaults months from now.
In addition to just learning the syntax, I started understanding the “Rust way” of doing things. When to copy and when to use references. When to switch to Rc and RefCells. How to use lifetimes (though I still mess them up sometimes). Most importantly, I’ve learned how powerful strong typing with enums and structs can be. A good initial data model makes writing the actual code so much easier.
Why I’m stopping
A browser is a hard to thing to build. It doesn't really have an end point. You could keep coding forever. There's always more features to add and bugs to squash. Even by constraining the scope to non-JS pages, I could still spend years working on it. Years!
Quite simply, I don’t have time for that. There are other side-projects I’d like to work on, and a mini-browser doesn’t help my day job at Mozilla (I work on Mixed Reality, not Servo). So it’s time to wrap it up.
What I’d like to do if I had more time
Even without supporting JS there's still plenty of work to be done. Currently the browser supports only inline and standard block layout. It doesn’t do Grid or Flexbox, or any sort of positioned content (absolute, fixed, relative, etc), or floats.
Since it doesn’t support JS, the mini-browser would be a good tool to convert webpages to PDFs, but that would require paged media support. Conceptually not difficult, but another feature with lots of little pieces that would take a lot of work.
Finally, the browser should theoretically be fast because it only uses a GPU backend and doesn’t execute any JS. In practice, however, it’s very slow because the browser doesn’t load anything in the background. All CSS, html, images, and other resources are loaded in the main GUI thread. To fix this I’d need to start learning how to do threads in Rust. Since that’s something I’d like to learn anyway, this is one feature I may come back to some day.
For now, however, I’m done. I feel pretty good about what I accomplished, and I tried to document all my work so that other’s can follow up after me.
Thank you
Thank you for reading my blogs about building a small web browser in Rust. You can read the whole series here.