AIUI the reason is, "we", collectively even though we don't all work on them, optimize browsers for speed above almost all else. Then, when all the advertising websites on the internet consume all that speed, we can't go back and have to optimized for speed even harder. All that optimizing for speed ends up consuming lots of RAM, from all the images, the speed-optimize DOM with lots of cross-linking, the JIT and its generation of native code paths, the endless layers of caches, etc. etc. at every point where a browser can choose between RAM and speed it will choose speed unless it's just impossible to choose it for some reason.
So even if you write good code in Electron, it still tends to eat resources like candy.
On the plus side, if you write good code, you will pick up all those optimizations too, which is not necessarily all bad. Running something like VSCode at all is a powerful testament to the browser ecosystem now. IDEs do a lot of very heavy duty lifting and need a lot of performance to do all their work. But you can imagine that when the same text rendering system that enables all that fancy & fast syntax highlighting and all the other decorations and features in the editor window is used to display a preview of a markdown file that said preview is probably going to eat way more RAM than your instincts may have guessed.