Comment by int_19h
1 month ago
Best part: a hello, world GUI app (a dialog with a textbox and a button that pops up a message box) is ~2.5 Mb on Win32.
This was something like 500 Kb back in 2000, but it's still a far cry from your ~200 Mb Electron hello world.
I remember some years ago that I was able to make this less than 1mb. It needed a little tweaking like upx but nothing very complex.
Lazarus should have been the golden standard for creating desktop apps. Every other solution I've tried is subpar either in licensing or costs in general, executable size and resource usage, non native components, extra dependencies etc
I think unfortunately what holds Lazarus back is the Pascal programming language. Although it is a very capable language that can hold its own against other languages, it suffers from a reputation of being obsolete.
It’s a pity that the C family of languages won out over Wirth’s languages. Pascal’s superior string handling alone would have saved us from countless security flaws.
And complex compiling. Pascal compilers are very fast.
Can someone recreate it in Go?
2 replies →
> it's still a far cry from your ~200 Mb Electron hello world.
I think that projects that ship packaged web apps but attempt to use the system native web views where available are really nice, like Wails: https://wails.io/ (so for example, on Windows it would use Webview2, so you don't have to package an entire Chromium install yourself)
Here's a comparison of how the distribution sizes change, Wails in particular also has way faster builds than something like Tauri: https://github.com/Elanis/web-to-desktop-framework-compariso...
That said, I wish we got more native software, or even something like LCL that can target Win32, GTK, Qt or whatever else is available. Sure, writing components that are available on a lot of platforms and work similarly everywhere is a pain for the developers, but I applaud the effort regardless, since the above solutions like Wails don't actually do anything for the memory usage and CPU cycles, whereas native GUI software is better for most apps that don't try to be very interactive.
I could even see myself using Lazarus/Pascal more if it seemed to have a more active ecosystem, right now I couldn't tell you what are the equivalents of something like Spring Boot for webapps, or even consuming Web APIs in client software, handling OAuth2/OIDC/JWT, seems like mORMot 2 would fit the bill the closest?
As I understand, the main problem with native web views is that you now have to deal with all the inconsistencies of e.g. Blink vs WebKit. Also, browsers tend to be more aggressively updated, which translates to potential app breakage due to bugs or deprecated features.
With respect to Lazarus, I agree that the ecosystem around it is not exactly great. It would be interesting to see LCL ported to something more modern that is reasonably simple, cross-platform and has good tooling. E.g. Go, much as I dislike it as a language, would probably be a great fit for something like that. And Pascal being fairly conservative and easy enough to parse, I suspect you could even automate this translation for the most part.
One thing I've always kind of wished for was a way to write the WEB dialect of Pascal in Lazarus --- then one could use Web2C --- if one could just link in platform-specific GUI libraries....
2.5 MB is for most of the Lazarus Component Library (LCL) with minimal size increases even as program complexity grows. For example, Dadroit JSON Viewer EXE is less than 6 MB while having complicated tree views, JSON handling, networking, and more. By the way, an empty CLI EXE on Windows is less than 50KB.
Why doesn't the linker strip out unused code?
I imagine it's for the same reason Delphi can't strip much, which is that it supports run-time reflection. You can create an instance of a class using a string of the name.
Forms (windows) are deserialized during loading, which relies on this mechanism.
Best part for me that it's a single file executable. I chose to do a thing in Pascal last year just because of this one killer feature. I made some initial attempts to achieve this with something else but I didn't find any modern tool that could do that without some weird, sometimes involved, sometimes straight up experimental steps.
I think Go will do it, but I indeed enjoy Free Pascal for this as well. It's also nearly trivial to set up cross compilation using FPCUpDeluxe, so I've shipped applications to clients on Windows when I do all development and compiling on GNU/Linux.
.NET can create self-contained executables pretty easily (via _dotnet publish_), both including the required framework assemblies and without them. But they'll still be comparatively large.
I couldn't find the right checkbox to click in VS.
Are those not just large zip files?
2 replies →
For JIT binaries it’s best to apply /p:PublishTrimmed=true which (sometimes massively) reduces their size. Applications written in AvaloniaUI or, nowadays, WinUI 3 can be compiled with NativeAOT which reduces the size and memory usage even further.
7 replies →
Maybe you're the person to ask. My Python Qt app is sluggish when it loads tens of thousands of values from SQLite. Various variations of pagination and lazy loading hurt usability. But isolating the issue and testing with C++ and Rust show that those two languages don't have the performance hit of Python.
I could use C++ and stick with Qt, but I'd much prefer Rust. Rust has no good Qt bindings. What are my options?
The app makes use of QV/HBoxLayout, QWidget, Qdialog, QPushButton, and other really standard features. It reads from the filesystem, reads and writes to SQLite, and outputs sound from mostly ogg files at various speeds (through VLC behind the scenes). I stick with Qt because I like how it integrates with KDE and other desktops flawlessly.
> What are my options?
> I stick with Qt
These come up on search results if you combine Qt plus the language.
Go:
* https://github.com/mappu/miqt
Java:
* https://github.com/OmixVisualization/qtjambi
Nim:
* https://github.com/jerous86/nimqt
* https://github.com/seaqt/nim-seaqt
Zig:
* https://github.com/rcalixte/libqt6zig
Thank you. I don't see Java as having a performance edge over Python ))
Same for the other languages - they likely won't have the performance of C++ or Rust. But I'll test them anyway, even just for the academic exercise the endeavour is worthwhile. Thank you.
9 replies →
https://areweguiyet.com/
Also did you test similar functionality in C++, I haven’t compared many implementations but I app I use that has an SQlite db being read with Qt(C++) is pretty sluggish whenever you touch the DB.
Maybe store the values in a dict and only read/write from sqlite when needed. Dicts are very fast in python.
This website is useless if accessibility compatibility is not mentionned.
Yes, that's what I'm doing. It's the initial load that is heavy.
I've also tried implementing lazy loading and pagination, with a pseudo-infinite scroll technique based on SQL LIMIT pagination, but the resulting CPU and memory spikes are noticeable.
> I could use C++ and stick with Qt, but I'd much prefer Rust. Rust has no good Qt bindings. What are my options?
There are several Qt binding for rust, for example cxx-qt. I haven't tried myself but it looks maintained. Why is it not good?
Otherwise, the most promising equivalent to Qt in Rust would be Slint.
Thanks. I forget why I discounted cxx-qt. It think it didn't support some common Q* object but I don't remember which. I'll experiment with it and with Slint, which I've been eyeballing anyway. Thank you.
Is Cython and/or avoiding copies an option?
Cython is a great idea, thank you. I'll definitely try that. The code is all properly typed anyway.
I'm not sure what you mean by avoiding copies. I'm rather stringent with memory, I don't have superfluous copies of data in memory. Or did you mean something else?
Thank you.
2 replies →
More generally, which all tools that can target multiple platforms, produce relatively small binaries for simple applications? And which of these are lean themselves?
May be I am doing something wrong, but I had installed Android Studio, then Android emulator, SDK, etc., and before I could get a hello-world app to compile, some 30 GB were gone from my disk space.
If it comes to it, I do not personally mind using multiple tools and code for different target platforms, as much as (a) both the tools themselves and the binaries generated are lean, and (b) the development tooling itself is on a single platform just so that I do not need to maintain multiple hardware. (I currently use Windows, would likely need to move over).
Thanks.
Java perhaps? That was one of the core promises of the Java ecosystem.
> produce relatively small binaries for simple applications
The problem is that you need to have a huge Java runtime installed or use something like Jlink which still produces very large binaries for GUI apps.
I think wxWidgets is the Lazarus alternative that is the closest to what grandparent was asking for.
https://wxwidgets.org/
2 replies →
Who remembers Steve Gibson's 'little corner of the web'? He wrote super small Windows applications in assembly: https://www.grc.com/smgassembly.htm
Definately remember it fondly - and Jeff Duntemann who continues to update and publish his definitive works on learning assembly - the latest edition/revision is: "x64 Assembly Language Step by Step" - https://www.contrapositivediary.com/?page_id=5070
Vividly!
In particular, his tech e-mail announcement/newsletter was where I first learned of a small startup w/ the unlikely name of "Google".
That’s a lot. I don’t know the specifics of Lazarus, but this typically screams static linking with everything and the kitchen sink being thrown into this one binary. Entire cross-platform runtime, GUI assets, metadata, etc. Could be a fat debug build, too.
It was the common complaint about writing VCL apps in Delphi - that single message box app would be 0.5MB binary.
But that was the static overhead of VCL core library and the benefits were considerable compared to writing raw WinAPI.
And unlike MSVC 16kB WinAPI executable you didn't have chance of sudden surprise "oh, but you need to update msvcrt.dll to run this" because Delphi (and Lazarus/FPC) default to statically linking the runtime
That's indeed a statically linked binary. Release, with smart linking (so only things that are actually used are linked; otherwise it'd be ~20 Mb), debug symbols stripped. Measuring .exe size when linking dynamically would kinda defeat the purpose of the experiment, since you'd still need to distribute the DLLs to the users for any real world app.
Not Pascal but here is something I wrote on the same lines in C++: https://latedev.wordpress.com/2011/10/06/simple-windows-dial...
But if you don't target windows, but the web as target plattform, you will need just 53 bytes that will work, wherever a browser works.
<input type="button" onclick="alert('hello world')" />
Even if you do target windows, tauri apps can be a couple megabytes
Now do a data grid backed by a database.
Just some lines more? I am sure modern LLMs can print out tons of different versions for your specific usecase and it will be way less than 2.5 MB.
HTML and JS is compact. The browser is not. But often installed already, so my PWA is very small as a result, but behaves quite native.
(But if you mean, that Lazarus can do that easily with a GUI, that would still be cool. Can it?)
Can't you still do much the same with WinForm, or maybe GTK?
With WinForms you can do much better, in large part because .NET itself ships with Windows and thus the app can just rely on it being there, but also because C# compiles to bytecode rather than native code (so it's not exactly a fair comparison). Anyway, the identical hello world GUI app in C#/WinForms is ~11 Kb.
With Gtk, no, because it implements all widgets by itself rather than wrapping Win32, so it'll necessarily be larger. Also, statically linking it can be a pain (and AFAIK isn't even supported in Gtk 4 anymore).
Even if C# compiles to bytecode, NGEN has been part of the framework since version 1.0, although using strong named assemblies might be bit of a pain.
Then there is .NET Native and Native AOT.
1 reply →
Is that statically linked or dynamically link? If the later, does it include all the libraries and assets it uses?
Does it have dark theme support and does it sync it's theme with the system one?
Not with the Win32 backend, since those widgets themselves don't have that notion.
Qt backend should be able to do that, though (but then of course you need all those Qt DLLs).
Windows widgets don’t have dark mode support on Windows?
3 replies →