5 ms·
The site is amazingly fast (at least subjectively), even though there must be a higher traffic coming from HN. Has anyone inspected the code to see how it's don
by dark_c 15y ago
The site is amazingly fast (at least subjectively), even though there must be a higher traffic coming from HN. Has anyone inspected the code to see how it's done and if there's some kind of a web framework for D?
- hasenj 15y agoIt looks like web.d implements the response handler from scratch, so I doubt there's a framework. Maybe a framework will be extracted from this in the future. It looks like there isn't even a template language -- it seems to build the html using the plain old string concatenation method. html.put( `<tr class="thread-post-row`, (post.info && post.id==selectedID ? ` thread-post-focused thread-post-selected` : ``), `">` `<td>` `<div style="padding-left: `, format("%1.1f", OFFSET_INIT + level * offsetIncrement), OFFSET_UNITS, `">` `<div class="thread-post-time">`, summarizeTime(post.time, true), `</div>`, `<a class="postlink `, (user.isRead(post.rowid) ? "forum-read" : "forum-unread" ), `" href="`, encodeEntities(idToUrl(post.id)), `">`, truncateString(post.author, 20), `</a>` `</div>` `</td>` `</tr>`);
- CyberShadow 15y agoI plan to move to HTML templates in a future version. It shouldn't affect performance.
- EnderMB 15y agoIt's probably not the deciding option, but the front-end code is only just over 20K because outside of a few images and a stylesheet there's very little going on. A lot of Web Designers today tend to completely forget that page size matters, and that just because many of us have broadband connection it's no reason to throw JS and screen size images everywhere.
- judofyr 15y agoHacker News is smaller, yet takes longer to serve: http://cl.ly/31360A1E2s2j031s0S2O http://cl.ly/31360A1E2s2j031s0S2O
- EnderMB 15y agoI didn't say that it was the underlying reason, but it's nice to note that even though the page looks nice it's also small and efficient, especially when you compare it to more established forums.
- tintin 15y agoFunny that people notice this. I think this is how all pages on the internet should be! Lately I'm getting tired of all those fancy Javascript pages or pages build on bloated frameworks. The speed of this forum has nothing to do with D. You can achieve this in a language like PHP as well. Just skip the bloat (server and client side).
- CyberShadow 15y agoHere are some of the things that play a part in the forum's performance: * Optimized and deflated static resources * Deflated HTML output * SQLite prepared statements * Integrated HTTP server (although it's currently in front of an Apache proxy) * An optimized string builder (https://github.com/CyberShadow/DAppenderResearch https://github.com/CyberShadow/DAppenderResearch) * RAM cache of frequent DB queries While there are equivalents available for interpreted/CGI languages (e.g. opcode caches, memcached), there is still a significant performance advantage. With a warm cache, most pages can be written out in under 5ms, and the busiest in under 50. For some perspective, the time needed to compose the busiest view (threaded or split-view) halved when I moved from naive string concatenation to an optimized appender.
- dkhenry 15y agoGreat work. I wonder if there is a way to turn this into a more general purpose framework then just serving up one specific forum.
- CyberShadow 15y agoYes, there are way too many things hard-coded at the moment. I want to refactor all of it out into templates, config files and library code. There's apparently some interest of adopting some code into D's standard library, too.
- andralex 15y agos/some/a ton of/
- dkersten 15y agoIn browsing on an android device and its incredibly responsive for me. Much more than other sites ive browsed on this phone today.