46 ms·
Games are also representative of the apps that actually squeeze the performance out of CPUs. When you look at most desktop apps and Web servers, you see enormou
by pcwalton 10y ago
Games are also representative of the apps that actually squeeze the performance out of CPUs. When you look at most desktop apps and Web servers, you see enormous wastes of CPU cycles. This is because development velocity, ease of development, and language ecosystems (Ruby on Rails, node.js, PHP, etc.) take priority over using the hardware efficiently in those domains. I don't think this is necessarily a huge problem; however, it does mean that CPU vendors are disincentivized to optimize for e.g. your startup's Ruby on Rails app, since the problem (if there is one) is that Ruby isn't using the functionality that already exists, not that the hardware doesn't have the right functionality available.
- munchbunny 10y agoI don't necessarily agree that it's a problem of the language ecosystems. In my experience games are one of the few areas where it is likely to be CPU bottlenecked and not I/O bottlenecked. My sample size is only the set of projects that I've personally worked on, but in the projects where I have intentionally profiled where the time is being spent, I have only ever run into UX-impacting CPU bottlenecks when working on games. This is spanning code I've written from assembly all the way up to Python. Not counting JS because the DOM is a bit of a black box to me. In almost every other case, the bottleneck was not being able to pull data out of physical storage or some network store fast enough. In some cases it was not being able to pull data from RAM fast enough. In a few cases it was not being able to pull data from a database fast enough due to needing to cover too big of a table, which I lump into the "waiting for I/O" category under the lightly investigated hypothesis that it's not because the CPU is having trouble iterating over the indices, but because the database can't keep the whole index in memory.
- koolba 10y ago> My sample size is only the set of projects that I've personally worked on, but in the projects where I have intentionally profiled where the time is being spent, I have only ever run into UX-impacting CPU bottlenecks when working on games. Try out any "enterprise" app that thinks its a good idea to load 25,000 widgets on one page. That'll show you the meaning of "CPU bottleneck".
- wolfgke 10y ago> Try out any "enterprise" app that thinks its a good idea to load 25,000 widgets on one page. That'll show you the meaning of "CPU bottleneck". Depending on the implementation it might also be a GPU bottleneck.
- nitrogen 10y agoIt's pretty crazy how video games can display thousands of objects and millions of vertices at 100+fps, yet web browsers and applications can struggle to display more than a handful.
- pcwalton 10y agoYep. That's largely because 2D vector graphics APIs from the '90s are poor fits for GPUs (and stream processors in general, really).
- Tloewald 10y agoIf you have a look at the code on many websites the answer is ludicrous amounts of bloat.
- ssalazar 10y agoIts not crazy when you consider typical video game economics (hundreds of developers/long dev time/high budgets/high price per unit) vs. typical website economics (handful of developers at best/short dev time/low budget/microscopic price per "unit"). Video games are often intimately tied to the underlying hardware/software stack allowing further optimization whereas the same webpage can often operate unaltered on a multitude of devices. And video games are often judged by how many "objects and vertices" they can show and how fast they can show them, whereas websites have other criteria.
- sbierwagen 10y agoThat's because the video game engines doesn't have to be hardened against malicious asset files. All the code in a video game runs at the same permissions level, which you definitely can't say about a random page on cnn.com.
- pcwalton 10y ago> In my experience games are one of the few areas where it is likely to be CPU bottlenecked and not I/O bottlenecked. Agreed, in most cases. That's why I'm not sure what I described is really a problem :) (I do think that mobile apps and the client-side portion of Web apps, for example, are often CPU/GPU-bottlenecked, though.)
- munchbunny 10y agoYou're right, I think we generally agree. I was just picking at a nuance of what you said about wasted CPU cycles. Yes, some languages and toolchains these days are less efficient to trade for ease of development, but from my experience it seems like I/O to RAM/disk/network is still 80% of the problem and "less work per CPU instruction" is 20% of the problem.
- Retric 10y agoI have seen plenty of 10x speedups in most apps from trivial changes. If you fail to use CPU cache correctly then can be getting ~1% utilization or less per logical CPU which is still plenty fast for the core logic of many applications.
- shmerl 10y agoModern games load GPU more than the CPU though.
- MBCook 10y agoDepends on the game and what's going on, but even with GPU heavy games the CPU can do a ton of work just getting all the data ready and packaged up for the GPU to chew on.
- shmerl 10y agoYes, decompression can be a common load.
- duaneb 10y agoCausality points both ways, though. Games use the GPU because that's where the compute power is—hence, that's why graphics are so emphasized over other features. GPUs are so powerful to meet the needs of gamers. There's nothing inherently faster or better about a GPU because most tasks don't parallelize that easy—it just so happens that the tasks that DO parallelize easily are highly emphasized.
- deleted 10y ago[deleted]
- nostrademons 10y agoInterestingly, the one thing that typical web frameworks do do very frequently is copy, concatenate, and compare strings. And savvy platform developers will optimize that heavily. I remember poking around in Google's codebase and finding replacements for memcmp/memcpy/STL + string utilities that were all nicely vectorized, comparing/copying the bulk of the string with SIMD instructions and then using a Duff's Device-like technique to handle the residual. (Written by Jeff Dean, go figure.) No idea whether mainstream platforms like Ruby or Python do this...it wouldn't surprise me if there's relatively low hanging fruit for speeding up almost every webapp on the planet.
- MichaelGG 10y agoWhy is this even a thing? Copying and the like is such a common operation. Why don't chip providers offer a single instruction that gets decoded to the absolute fastest way the chip can do? That'd even allow them to, maybe, do some behind-the-scenes optimization, bypassing caches or something. It's painful that such a common operation needs highly specialized code. I know you can just REP an operation but apparently CPUs don't optimize this the same way. This is too obvious an issue, so there must be a solid reason. What is it?
- corysama 10y agohttp://stackoverflow.com/questions/8858778/why-are-complicated-memcpy-memset-superior http://stackoverflow.com/questions/8858778/why-are-complicat... counter claims https://news.ycombinator.com/item?id=8683565 https://news.ycombinator.com/item?id=8683565
- MichaelGG 10y agoAh that thread is great and answers my question. TL;DR seems to be that rep+mov is as fast as anything now.
- Tloewald 10y agoThis seems like something that compilers should do and CPU instruction sets should not.
- flukus 10y agoThat's because on web apps we have plenty of CPU cycles to burn. Our performance bottlenecks are disk/database and network speeds.