by karteum · 5y ago · 0 comments
However... "Low CPU and memory footprint (...) memory usage is under 20 MB for a Hello World program" : I am the only one who still thinks this is huge ? (-> https://tonsky.me/blog/disenchantment )
IMO there's a tradeoff: we could be writing all our programs in C, still. But it would be enormously difficult and there'd be way more bugs. On the other end of the spectrum we can be lazy, use web tech everywhere and never optimise our ballooning JS codebases. This feels like it's at least somewhere in the middle.
OT but a bone to pick with that article:
> Modern text editors have higher latency than 42-year-old Emacs. Text editors! What can be simpler? On each keystroke, all you have to do is update a tiny rectangular region and modern text editors can’t do that in 16ms. It’s a lot of time. A LOT.
That isn't what my text editor is doing, though. It's doing autocomplete suggestions, linting code as I type... all sorts of things we never had a couple of decades ago and are huge productivity boosters. Sometimes I feel like people forget that.
I remember an article a couple of years ago where someone rigged up a camera to measure key press to screen update on different machines and the results were eye opening.
edit: found it http://danluu.com/input-lag/. The Apple ][ ties for first place with an iPad Pro.
"Almost everything on computers is perceptually slower than it was in 1983" https://threadreaderapp.com/thread/927593460642615296.html
* When used with an Apple Pencil (30ms). When used with touch it drops to 70ms.
Also, it's worth noting that there's a very limited list of devices tested there and it heavily skews Apple.
What on earth have we done to ourselves?
That's a big part of what we've done to ourselves. And this makes computers better for a whole lot of people.
First, all those things sans high DPI functionality existed in 1998.
Second, most of Electron apps don't benefit from these theoretical advancements.
Preemptive multitasking existed in 1998 and worked every bit as well as it does today. Even in MS Windows.
Security, nah. We have more attack vectors than at any point in the past. And just more crapola caked on to "protect" against those.
https://www.fltk.org/doc-1.3/fluid.html
You pretty much draw the UI in fluid and fill out the callbacks. Yeah it's C++ but it's not particularly esoteric C++.
No need for that - you could use Zig or Rust. Though both need a better GUI frameworks, but it's certainly more efficient with them.
I moved from sublime to atom to VS code, but eventually settled on Vim because I was able to get the same features (that I used) while getting almost instant response. A feeling that has completely changed how much I enjoy writing any sort of text.
But eventually wasn't able to get the same code completion, and searching was also a bit more painful.
How do you go about that? Would you mind sharing your setup? :)
It's conceptually similar to sketching out the design of your code with a pen and paper or whiteboard. First write it quickly, then make it correct.
For searching, use SilverSearcher / fzf
For C/C++, could use QT Creater or KDevelop too, which I think are pretty good in latency.
BEFORE the typed character shows up? Are you sure?
16ms should be an absolute upper bound for a character to show up. Everything else comes after.
Another example is the Enlightenment window manager. It was considered a little heavy, but good looking. But because there was a large hiatus in development, it got "stuck in the past" and now, it is one of the lightest there is.
I'm just kidding. Don't want to start a fight here.
But those wars are long over anyway, these days. One might just as well fight over whether the monolith on Earth's moon is better than the one on Europa, or vice versa.
We had them.
> we could be writing all our programs in C, still.
You don't need to use C, there are other languages. For example a hello world in Free Pascal[0] (a natively compiled language with no runtime or other dependencies, which supports object oriented programming and has RTTI rich enough to implement automatic object serialization, semi-automatic memory management, strings that know about their encoding, etc) is just 32KB.
Some time ago i wrote Fowl[1], a mostly complete recreation of the OWL toolkit that came with Turbo Pascal for Windows, the demo program of which is around 80KB.
Of course for a more realistic (and MUCH easier to use and develop with) approach, you'd need something like Lazarus[2]. A minimal application in Lazarus is 2.18MB. This might sound too big... and TBH it is, but the size doesn't grow too quickly from there. For example a profiler i wrote recently for Free Pascal applications is... 2.16MB (yes, smaller, why? Well, because i replaced the stupidly huge default icon with a smaller one :-P and without the default icon a minimal application is 2.05MB so the profiler added around 100KB of additional "stuff").
> It's doing autocomplete suggestions, linting code as I type... all sorts of things we never had a couple of decades ago and are huge productivity boosters
FWIW we had those, Visual Basic (or even QBasic) would format your code as you type it, Visual Basic 6 and Visual C++ 6 would profile auto-completion (VB6 even for dynamic stuff), etc. Only issue with C++ was that sometimes it wouldn't work around complex macros.
But modern editors do a bit more, still no excuse for being that sluggish. Lazarus does pretty much everything you'd expect from an IDE with smart code completion (e.g. things like declaring variables automatically, filling method bodies, etc) and code suggestions yet it runs on an original Raspberry Pi.
Now i'm not saying that you should not be using whatever you are using or that you should code on a Rasberry Pi or even to switch to Free Pascal / Lazarus (which honestly is far from being free of issues), but i think that you're overestimating what tools do nowadays and many people are so used to running slow and bloated software that take it for granted that things should be like that and cannot even imagine things being better.
[0] https://www.freepascal.org/
But it is also an interesting thing to mention because in the last two C++ jobs i had where Visual Assist was preinstalled on my machine, i always disabled it because it was slowing down Visual Studio too much and the functionality VS provides is more than enough - VA does provide a bit more, but for me wasn't worth the slowdown.
One of my key learnings with alternative languages is to always use the SDK tools from the platform vendor, everything else comes and goes, while playing catch up all the time.
Even so, shouldn’t it be able to do that in 16ms?
Do modern graphics drivers for X or Wayland hand off font rendering to the GPU? They probably should -- it's maybe 100 or so small textures per font-selection, 150KB or less prerendered with 3-bit alpha, and maybe 100 loaded up into graphics RAM at a time -- 10MB is nothing, really.
It's just that text editors of the modern day are programmed by people who prefer to not write it that way - mainly because it's quite hard, and the modern OS doesn't usually fit well into this framework of rendering for multi-tasking. And it takes more effort too.
Much easier to rely on a UI framework which adds overhead. The expectation is that the user probably won't care, and prefer that the software be more feature rich.
In the BASIC heyday, there existed compilers for BASIC (some of them written in BASIC). These didn't ship in the ROM images either, they were third-party apps.
Also, there was a really fantastic question asked in the last Cosmopolitan thread, but it wasn't answered; what's the answer to it?
Some friend of mine like it :D.
But I'd like that more if it was Scheme.
It might a bit rude to remind that, but the same person saying aforementioned words about huge memory usage promotes the Skija [1], Java-based GUI toolkit, which is even worse in memory consumption than electron (jb-compose provided examples, even in release builds).
[0] Memory Footprint of GUI Toolkits - https://szibele.com/memory-footprint-of-gui-toolkits/
[1] Graphics for JVM - https://tonsky.me/blog/skija/
Electron has been around what? 7 years?
I'm curious what kind of magic is happening where node.js is in the picture yet the executable comes out at ~20MB. Is it simply a bundle of wrappers for most of Qt with Node.js being required to be installed separately? Is it purely UPX compression?
[0] https://stackoverflow.com/questions/450455/minimal-qt-execut...
The entry point in ther starter kit calls qode (a fork of node), which talks to qt via napi (node's API for c++ bindings). It can be distributed as binaries via the *-deployqt toolchains.
So for distributable binary size in disk, we're probably looking at something in the ~100mb range with no UPX shenanigans.
So, tl;dr not as magical as I initially assumed. The trade-off between "bloat" vs ability to use web paradigms feels like a reasonable one. Overall pretty cool stuff.
(2560 * 1600 * 4) / 1024 / 1024 = 15 MB
So no, that is not huge for a modern GUI program.
IIRC on macOS it consumed less than 15MB.
This means that you can't use the OS provided facilities (as they all have different metrics) and have to bundle good font rendering engines (if you care about non-us-ascii people) - that means already ~7-8 megabytes at the bare minimum for that.
RAM is cheap and plentiful. If you don't use it, its value is almost zero (the "almost" comes from OS-level caching of files and CPU-level cache misses of code).
Yet if you use all of it, its value is also zero - to every other program on the same computer. Don't be a dick; Use what you need, not all you can.
The reduction of the complex trade-off between memory use, CPU, disk, development environment, ease of deployment, and the dozen other variables that go into a choice like picking what toolkit to use to "don't be a dick" is so absurdly simplistic. It's a trade-off - not a single-axis "good or bad" decision.
Moreover, 20 MB of memory usage is going to be an acceptable trade-off for the majority of HN users, who skew webdev, not embedded.
If I look at today's top seller computers in Amazon for my country (France, 6th economic power in the world), the top two models both come with 4G of RAM (a chromebook, and a win10). The windows one will already use ~2gigs just for the OS. That leaves 2 gigs of RAM for your apps.
And that's for computers being sold today - they will still be in use in five years.
I have fond memories of my DOS days and the simplicity inherent in a single tasking environment, however nowadays operating systems allow for more than a single application to run at the same time and each application should play nice with the system resources, so even if RAM is cheap and plentiful it doesn't automatically mean that every application should feel entitled to it.
(and also even during the DOS days we had TSRs which had to be RAM conscious too)
Yes, you shouldn't be a bad neighbor, but the OS will generally move things around to accommodate you as necessary. RAM is an afterthought for most of these applications for a reason.
This attitude is like buying a sports car and never redlining it.
I'm not sure what you mean with that. The OS will not "move things around" to the point where the resource abuse wont be noticeable, all it can do is swap stuff to the disk, perhaps compress some RAM and maybe unload any cold code (though code doesn't that that much RAM) and all that take time, slowing down the system.
> RAM is an afterthought for most of these applications for a reason.
Yes and that reason is disinterest from the application developers for RAM usage.
> This attitude is like buying a sports car and never redlining it.
Sports cars have nothing to do with this, i do not see the relevance.
If you find yourself in a situation where your OS is actually shuffling things around for your system to function you will find your performance and desktop experience has gone to absolute dog shit. It's entirely likely that the user will actually hard reboot the machine because they conclude it has frozen.
The absolutely only way to have a nice desktop experience in Linux is to ensure you have enough ram for all the things you intend to run at once which means have at least 8GB-16GB of RAM and don't run too many app once from people who think unused RAM is wasted RAM.
This is a perfect analogy. To stretch it, the majority of sports car owners are developers. The vast majority of your users are not.
Also HN: "The MacBook Pro is worthless if I can't get it with at least 64GB of RAM."
But the value is also zero if you're using extra for no benefit. Actually it's negative, because it prevents other programs from using it.
You should try to use all your RAM, yes, _but in ways that are actually useful_. The OS can always use leftover RAM for caching frequently used files if you don't have a better use for it.
After doing web dev for years I wrote a desktop application with Qt.
It's not massively complex (but a lot more complex than a hello world) but when it's running the memory usage is very low even compared to 20mb
jart@debian:~/scratch/qtproject$ qmake -project
jart@debian:~/scratch/qtproject$ make
jart@debian:~/scratch/qtproject$ ldd ./qtproject | grep -Po '(?<==> )[^ ]*' | xargs ls -alH | awk '{x += $5} END {print x / (1024 * 1024.)}'
59.5916
That's bigger than I expected to be honest.- Emacs (with 251 open files and IRC running): 100MB
- Activity Monitor: 98MB
- Word: 227MB
- Spotify: 465MB
- Slack: 526MB
- Thunderbird (not Electron, but a similar weird browser hybrid thing): 663MB
- Teams (which appears to be Electron): 747MB
I'm not seeing too much of a blur here. The worst chat app (Teams) is using ~7x the RAM of my primary code editor that also is doing chat :).
You can't just compare Emacs with Spotify here, I can't even scroll a list in Spotify without seeing it disappearing on me momentarily, that says more about Spotify's engineers or project managers than it says about Electron.
Teams and Slack kind of address the same problem and I'm seeing wildly varying numbers reported by you, without knowing anything about how you are using those apps those numbers are meaningless in my opinion, and if you think they are meaningful then clearly you can achieve different results despite addressing the same use case with the same technology stack.
Also there's "chat" and "chat", there's a reason ~nobody uses IRC anymore compared to Slack, they are not the same thing, and it's not just that Slack is easier to use.
Electron does not provide that much more desired features than apps from 25 years ago.
That's true, but advanced GUI features aren't Electron's selling point. It's used because it offers easy portability and the ability to leverage web-dev skills.
It can be assumed that anything running on the desktop has or will have vulnerabilities. The rise of web applications has been partially due to the assumption of great sandboxing.
I look forward to this project doing well, but it’s not the first time I’ve seen an electron competitor on HN promoting it being Node-based. Node isn’t sandboxed by default.