• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
  • entries
  • comments
  • views

Return to Fast-Land

Sign in to follow this  
Followers 0


A few days ago, the Epoch compiler could self-host in about 60 seconds.

My last run of the self-hosting process clocked in at 6.59 seconds - nearly ten times faster than when I started out. That's not bad for a couple afternoons worth of work.

As I suspected, there was a lot of lazy nonsense in the compiler that led to the slowness. The only data structure I implemented was a singly linked list, so lots of things were O(n) lookups or O(n^2) or O(n!) depending on how stupid the surrounding algorithm was.

I've cleaned up the most egregious time-wasters, which accounted for a major portion of the speedup. In addition to just making things less dumb, I've been adding hints and other shortcuts to minimize the number of list traversals being done across the board. There's a lot of code that does bad things, like iterate across the list of all functions looking for the function's return type, and then immediately forgetting where that function lived in the list and looking up something else about it, traversing the whole list from the beginning.

A little more effort shaves off some time and leaves the high watermark of 6.52 seconds. When 0.07 seconds is enough to get me excited, it's probably time to start looking for other ways to optimize. I have a long way to go to reach my target of sub-second compiles.

One trick I've pulled out a couple of times is rigging up the JIT system to do a kind of crude instrumentation profiling; with a simple #define I can turn on a mode where all JIT code tracks how long it runs for. This greatly inflates execution times because the overhead is nontrivial, but the data is still mostly useful - and probably will continue to be, up until the point where I'm pushing under a second.

There's a serious danger to trying to make a compiler faster, and that is the dreaded miscompile. Whenever a compiler emits something that is just plain wrong, it's a scary thing; and when relying on a compiler to compile itself, it's easy to accidentally wind up with a chain of bad compilers that have slowly worsening bugs embedded in them.

I actually wasted a couple of hours earlier chasing miscompiles that I introduced during optimization attempts. So there's a fair bit of lost time that could have been spent making things faster, but oh well.

6.24 seconds. It's now 2:45AM and I'm starting to get fuzzy. The type checker is now down to less than 1.7 seconds of runtime, which is well past my goal of 2 seconds for the day.

The clock strikes 3:20AM and I've gotten to 6.18 seconds. A few more tweaks and I hit 6.14.

Twenty more minutes of hackery only nets me 6.13 seconds. One one-hundredth of a second is nice, but not nearly enough. It's time to break out the profiler and study the results closely.

Optimization is often an exercise in judicious caching; the compiler is no exception. Carefully storing off commonly-recomputed data gets me all the way down to 5.9 seconds. A little more and I'm clocking 5.68 seconds.

Another important optimization trick is knowing how to balance long chains of conditionals. If the most common case is buried in an "else" all the way at the end, the code has to run through all the less common cases to get to it. Rearranging a few conditionals so that the most common options are first gets me down to 5.59 seconds.

The lexer is particularly painful at the moment, so I take some time to clean up some of its performance sins. 5.27 seconds. Cleaning up similar sins in the parser gets things down to 5.12 seconds.

It takes until 5:30AM to reach 5.02 seconds. Progress is painfully slow, and I'm starting to get a little discouraged. I had hoped that there was enough low-hanging fruit to get further than 5 seconds, but it's starting to look like I'm going to have to dig real deep to get to my desired target time.

One thing that consistently shows up on the profiler as being nasty is the string table system. The Epoch runtime uses a pool of statically known strings for various purposes; during compilation, we need to do many lookups into this pool. Since my only data structure is a linked list... things are painful.

It turns out that converting the search function from recursive walking of the linked list to iterative traversal gains a decent chunk of speed; 4.89 seconds just as the 6:00AM hour rolls around.

I spend the next half hour or so implementing a basic prefix trie data structure. This will be used for lookups into the string table. It's a solid win over even the iterative search function - landing at 3.52 seconds. Throw in another half hour worth of minor fiddling, and we're at 3.46 seconds.

Another cursory skim-through of the profiler results shows that we're wasting a lot of time looking up metadata for variables; this can be trimmed back a lot to search a smaller subset of the data, netting a speedup that brings us to 3.42 seconds.

I found some easy improvements to my trie implementation; minimizing the amount of string processing going on helps attain a compile time of 2.95 seconds. The clock reads 7:15AM and I'm well past the point of being overly tired.

I will threaten to hang up my hat for the night (morning?) and post this entry. Don't be shocked if I wander back in soon and post a comment with another speed record.

Sign in to follow this  
Followers 0


Caught a couple hours of sleep and got back to it. 2.58 seconds is the current record.

Share this comment

Link to comment



I am beginning to wonder about your high I.Q. and if you hit 100 hours per week on this - LOL


This is a very interesting and inspiring blog that you keep. 


Share this comment

Link to comment

Somewhere over the past 24 hours I shaved things down to 1.5 seconds. No, I'm not sleeping enough.


Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now