6 ms·
Show HN: detecting cache latency inside a Web browser
- polyfemos 9y agoAnd with the latest iOS 11.2.2, this (admittedly cool) piece of code no longer works. Still works on the latest MacOS (10.13.2) though.
- Marat_Dukhan 9y agoHmm...I just tried on iPhone 7/iOS 11.2.2, and it still works, albeit takes very long to start.
- mherrmann 9y agoOn my OnePlus X Android phone: https://imgur.com/a/C1hb7 https://imgur.com/a/C1hb7
- chrisper 9y agoOn my i7 8700k https://imgur.com/a/D71v1 https://imgur.com/a/D71v1
- kaoD 9y agoOn my pretty outdated Core 2 Duo Q9300: https://i.imgur.com/HQXm5FU.png https://i.imgur.com/HQXm5FU.png The CPU is advertised as 6 MB L2 cache[0] but it has "L1 = 4 x 32 KB 8-way set associative data caches and L2 = 2 x 3 MB 12-way set associative caches (each L2 cache is shared between 2 cores)"[1]. You can clearly see the constant time access to L1 cache up to 32KB. Then grows to (linear?) access time up to 2MB (where it still fits in one of the L2 caches) and then again a different (log-like?) function from there on. This is really neat. [0] https://ark.intel.com/products/33922/Intel-Core2-Quad-Processor-Q9300-6M-Cache-2_50-GHz-1333-MHz-FSB https://ark.intel.com/products/33922/Intel-Core2-Quad-Proces... [1] http://www.cpu-world.com/CPUs/Core_2/Intel-Core%202%20Quad%20Q9300%20EU80580PJ0606M%20(BX80580Q9300).html http://www.cpu-world.com/CPUs/Core_2/Intel-Core%202%20Quad%2...
- Marat_Dukhan 9y agoAuthor here. I made this demo and a related matrix-matrix multiplication demo [1] back in 2015 for Robert van de Geijn's Linear Algebra: Foundations to Frontiers MOOC class [2]. In the light of Spectre attack and recent browsers' changes to reduce precision of timers, I remembered of this project, and decided to check if it still works now, 3 years later. Surprisingly, it still works well! The source code is available on GitHub [3]. [1] https://maratyszcza.github.io/laff-demos/dgemm.html https://maratyszcza.github.io/laff-demos/dgemm.html [2] https://www.edx.org/course/linear-algebra-foundations-frontiers-utaustinx-ut-5-02x https://www.edx.org/course/linear-algebra-foundations-fronti... [3] https://github.com/Maratyszcza/laff-demos https://github.com/Maratyszcza/laff-demos
- madez 9y agoCould you make the website viewable without JavaScript? Edit: I think the downvotes are unjustified. For clarification, if that wasn't clear by context, I don't expect to get the JavaScript test results from my computer while viewing the website without JavaScript. Demanding that would obviously be nonsense. Rather than that I assume there is information on that website that is interesting to read even without using JavaScript personally. Or is using JavaScript now a requirement to learn about JavaScript?
- StavrosK 9y agoI guess you'd have more luck if you had asked "can you make some examples accessible for those of us who don't run JS?".
- madez 9y agoI didn't know what to expect to see. I vaguely assumed to see some text and data. That's why I carelessly formulated my question like I did. Still, I think the difference is small and my question wasn't extraordinary.
- Cyph0n 9y agoIs there a particular reason why you can't enable JS yourself? Metered connection? Low-end machine?
- yeukhon 9y agoIs there plan to collect this data voluntarily? Would be interesting to see the different percentiles
- Marat_Dukhan 9y agoNo, it is a static web page, and all code runs only locally in your browser.
- Sephr 9y agoThis is similar to how I detected total CPU cores in 2013 to implement navigator.hardwareConcurrency: https://eligrey.com/blog/cpu-core-estimation-with-javascript/ https://eligrey.com/blog/cpu-core-estimation-with-javascript...
- chrisper 9y agoIs that Ram only or also L1 etc. caches?
- frik 9y agoOkay, so how can we deactivate ASM.js and WebAssembly? (in the light of Meltdown and Spectre) The config in Chrome is broken, WebAssembly cannot be deactivated anymore with chrome://flags/#enable-webassembly , setting it to "deactivated" and it's still active.
- Marat_Dukhan 9y agoAsm.js is not necessary, simple JavaScript interpreter is enough. This demo used to work before most browsers implemented optimizers for Asm.js
- rmrfrmrf 9y agoYou need to disable `SharedArrayBuffer` and `performance.now`, which Firefox already did.
- based2 9y agoMozilla Foundation Security Advisory 2018-01 Speculative execution side-channel attack ("Spectre") https://www.mozilla.org/en-US/security/advisories/mfsa2018-01/ https://www.mozilla.org/en-US/security/advisories/mfsa2018-0...
- wyldfire 9y agochrome://flags/#enable-site-per-process is a mitigation that at least raises the bar a little. :/
- TickleSteve 9y agoIts characterising memory accesses, so it will show up the result of using all the caches in the system. You would typically see larger latencies when the caches are not being effective. Multiple humps will indicate the presence of multi-level caches.
- jacquesm 9y agoSo, who thought it was a great idea again to use a mechanism intended for document transfer to run unsigned, unaudited code on just about every client in the world?
- deleted 9y ago[deleted]
- nicolaslem 9y agoTo be fair the problem is not related to web browsers. It's more about running code in general. I start to realize that running someone else's code means trusting the developer. No matter the amount of sandboxing and the layers of abstraction, eventually his code will be able to run as root using exploits that are yet to be discovered.
- jacquesm 9y agoSure, but until the advent of JS you at least knew whose code you were going to run. Now you are more or less required to run untrusted code just to get through daily life.
- kevingadd 9y agoAnd web platform people remain convinced that HTTPS transport encryption is sufficient to protect everyone, even though desktop app, OS, and bootloader people have been doing code-signing for something like two decades.
- krick 9y agoI would argue it is very much related to web browsers. Sure, your torrent-engine or audio-player can be vurnerable as well, but how likely is that? If this would be the case, I'd say that the developers of this audio-player have seriously fucked up, essentially have allowing the third party to run an arbitrary code on your PC — something is doubtfully necessary for an audio-player. The most important question would be — what do you have installed? And, sure, it could potentially be all kinds of malware, but then chances are you are fucked anyway — because installing a software, ironically, requires much more trust than opening a web-page. But in reality you (and billions of people around the world) have this thing called web-browser with JS enabled, where opening a simple text-document is basically indistinguishable from running a BTC-miner for the end-user. All these people are fucked right now and have been left to hang. All they can do is to ignore the news and hope it will just go away. It did seem to me a viable solution some 10-15 years ago, in the time of Web2.0. Now, after mobile apps have spread around the world — I reconsidered. Having an app is just better even if it's just the HN-reader. Even better, if it would be a single app for some common "news-aggregator-protocol", to fetch content from HN, reddit, etc. But it is not only not the case — I heard people say that this attitude is "killing the web". Well, if so, fuck you, web should be killed. It should have never existed at all in the form we currently have.
- esnard 9y agoSomewhat related: using the cache latency to estimate the CPU cache size. https://fromwhenceitca.me/cache_size/cache_size.html https://fromwhenceitca.me/cache_size/cache_size.html
- Yetanfou 9y agoThinkpad T42p with Pentium M 1.8GHz, 2MB L2 cache https://imgur.com/agxy8e7 https://imgur.com/agxy8e7
- Mister_Snuggles 9y agoI'd like to see some text explaining what I'm looking at. Based on the title, it's something to do with cache latency, but that doesn't really help me. What exactly is it measuring? How does it perform this measurement? What are the limitations of this technique? What are the wider implications of this? What uses does it have, both potentially nefarious ones and potentially beneficial ones?
- laCour 9y agoi5-4690K (L1 4x32KB; L2 4x256KB; L3 6MB): https://i.imgur.com/FUs1isW.png https://i.imgur.com/FUs1isW.png LG v30 (L2 2MB): https://i.imgur.com/q5R3bLY.png https://i.imgur.com/q5R3bLY.png