Joining the chorus on prepared statements. Also — set PRAGMA journal_mode = WAL once at startup, not per request. Saw it in the source already, good call. The next biggest win is indexing the foreign keys: posts.threadId and posts.author deserve their own indexes.
WAL was the biggest single win. After that, indexing the foreign keys cut thread-listing time roughly in half. We should also add an index on threads.lastpost — the forum index page sorts by that on every load.