2024-03-08 Go routines

Oddmu can be run as a static site generator. It walks the tree and renders HTML pages. For the 15000+ files on my blog (about a third of them files that are simply linked and not rendered), it took around 160s. I wondered whether it was possible to push it. How about starting a go routine that walks the directory tree, adding files to a tasks channel and then closing it; starting four or five worker go routines that take files from the tasks channel until there is nothing left to do; putting errors on a results channel and when they're done, putting a true value on a done channel; a watcher go routine that checks the done channel and if every worker is done, close the results channel; and the main program goes through all the values on the results channel and sets up some short-circuiting in the case of errors and otherwise it prints an animation. What a glorious spaghetti mess of code! I felt so smart because it was so hard. All those failure states I fixed. Endless waits because channels ran out of data and my code kept waiting. And now it runs in 74 seconds with the fans on. And I'm … I'm not quite sure what to think. Perhaps it was all a waste of time. Was it really worth it?

Suddenly I have my doubts.

I used just two workers and it was a bit less than 100s. I guess I'll just put that on a separate branch should I ever need to look at it again.

​#Oddµ ​#Programming