Ace, CodeMirror, and Monaco: A comparison of browser code editors (2021)
blog.replit.com
blog.replit.com
CodeMirror improved Replit's performance by a lot and by extension our retention. In fact, after releasing it to mobile in July[1] our weekly retention rate on mobile increased by a whopping 70%. That said, solve a lot of mobile usability issues so it's not all due to performance. On desktop however, it's a different story, we made sure to just have parity with Monaco and it still improved retention by %25, almost all due to performance!
If you like working on performance come work at Replit, we want people that care about the performance of our systems!
Adopting CodeMirror pushed us to write more in a more functional style that makes the code more fun and simple (not easy) in the shortrun, and more maintainable in the long run! My teammates write CodeMirror extensions for kicks and giggles, sometimes they end up releasing some "bret victor shit"[3].
If you like CodeMirror and end up using it in production, try to get your company to fund the project[4] and open-source as much as you can!
[1]: https://blog.replit.com/codemirror-mobile [2]: https://blog.replit.com/codemirror [3]: https://blog.replit.com/kaboomdraw [4]: https://marijnhaverbeke.nl/fund/
I had a similar kind of good experience with code-mirror. I was writing my first proper compiler, and making a total dogs dinner of it. As a distraction, I decided to try put together an editor with syntax highlighting with CodeMirror. In the process of just fitting my compiler to the CodeMirror recursive descent parser I ended up bringing my compiler back from the brink of disaster. It feels really nice when a framework/API has enough good-taste/-engineering built into it that it improves code that uses it :)
I'll be interested in seeing how the upgrade to 6 goes - I'll wait until it's officially released, though...
(People've been using said compiler + IDE for about ten years now)
- An Operational Transform (OT) based system built by Marijn (the creator of CodeMirror)
- A Conflict Free Replicated Datatype (CRDT) based system using Yjs built by Kevin Jahns (the creator of Yjs) - https://github.com/yjs/y-codemirror
OT Demo: https://codemirror.net/6/examples/collab/
Yjs Demo: https://demos.yjs.dev/codemirror/codemirror.html
Both are brilliant, but I'm a huge fan of Yjs - the number of different bindings to different editors (and state systems) is incredible. It's a great platform to build collaborative tools on and the big plus is offline editing support, you can have a document diverge significantly while offline and still merge successfully. OTs are a little more difficult to make work well for a significant period offline.
I don't know which of the above Replit use, I would suspect the OT version as they mention building a OT system for Ace in the article.
Also huge fan of yjs, but the implementation is not compatible with codemirror 6, only version 5 (AFAIK)
Unfortunately copy and paste doesn't work well on Firefox on Linux in any of these fancy editors because support for the primary selection is broken and Mozilla doesn't seem interested in fixing it: https://bugzilla.mozilla.org/show_bug.cgi?id=1593761
The article calls CodeMirror "lightweight" but the minified JS is still over 1 MB. If you want lightweight then you probably want something like CodeJar (https://github.com/antonmedv/codejar) which clocks in at 2 kB.
I did a quick check of a CM6 project (customizing the JS lexer) with the base options and a JS-derived lexer and it came out to 405k / 124k gzip. I wouldn't consider it especially lightweight but I think the size is reasonable for the feature set.
Here it is around 300kb inflated https://codemirror-basic-setup.replitfaris.repl.co/ using the basic-setup package, and I don't think this build tree-shakes.
Code for this build is here https://codemirror-basic-setup.replitfaris.repl.co/__repl
> Unfortunately copy and paste doesn't work well on Firefox on Linux
Code editing in the browser has plenty of valid criticisms, but that criticism is as pointless as saying it won’t work in Lynx. Use any one of the many many browsers that do support copy and paste.
> which clocks in at 2 kB.
You aren’t comparing like-for-like in terms of functionality. You might as well say just use a <textarea> tag which clocks in at 0.02kB.
> but the minified JS is still over 1 MB
From the article: Modularity, bundling, and footprint: “CodeMirror is built with modern technologies. You can even use ES6 modules to import it with no bundler involved. Lazy-loading features is a breeze; dynamic ES6 imports are all you need. The project is very modular and has a very slim core.”.
CodeMirror is relatively light, compared against Monaco: “Monaco is huge. monaco-editor and related libraries contributed a whopping 51.17 MB to our bundle size (5.01 MB when parsed + gzipped)”, in Monaco “lazy-loading features are not possible as far as I'm aware”.
Personally, I've found it to be really annoying.
Using VSCode as a desktop connected to a remote code server, or using JetBrains Projector, is the true sweet spot where you combine the remote capabilities with a native app. Also fits well with vim/emacs TUI-style dev.
If I were building an IDE today, I would absolutely be building it as a client-server app from day 1.
Why ? The last thing you want as a user when pressing a key in a IDE is to then wait for a network request.
What I'm referring to would be a caching view which both hides latency, batches communication for efficiency and perhaps even does some actions on the client-side buffer if it's deemed appropriate.
tmux is also amazing for spotty ssh connections. For example, I had to run long jobs over ssh through a VPN. Tmux means you don't need to worry about the connection dropping and losing your current process
> Using VSCode as a desktop connected to a remote code server, or using JetBrains Projector, is the true sweet spot
is a zero lag approach when it comes to code editing.
The only time a brief lag show up in the IDE are when you need to open a folder/workspace in an uncached directory which is easily ignored.
I’ve been banging the drum on this setup for well over 2 years. Happy to share more info if interested
I’m not suggesting JavaScript should be able to redefine keys without permission, but I can’t even disable CTRL+w as a power user…
Right now, someone with own parser/language analyzer (I have built parsers for several SQL dialects) has just Monaco to work with as LSP for CM6 doesn't seem to exist yet.
Will be closely watching CM development.
The LSP integration for Monaco is lackluster, it works, but isn't great. We thought LSP would work perfectly on Monaco only to find out that the Monaco APIs are very different from LSP APIs or even VSCode APIs. The 3rd party package out there is good, but you need a bunch of monkey-patching to make it work in an "IDE" environment.
thanks for releasing codemirror-vim! not having vim capabilities has been one of the longest standing blockers to me using anything web-platform based. i understand there are some vim plugins for various platforms, but great to see some efforts out in the open for codemirror6. https://github.com/replit/codemirror-vim
FWIW I've been toying with ANTLR. I used some of their community's example grammars to get started. Is it weird that grammars generally don't include test harnesses?
The circle of re-invention keeps coming around.
They are great for viewing code, but I'm not convinced they are good for writing code.
I've recently experimented with the PR feature inside JetBrains IDE's. It allows one to navigate quite well without having to actually switch branch. Like it so far, nice to see the whole file and related files, not just the diff.
Makes it really easy to get a new project up and running. "docker compose up", and point pycharm to the python container as the remote interpreter and it's up and running. No longer having to spend a few days getting the local env up and running on some developer's unlucky configuration of software+hardware.
So while I still use a local IDE, and run most of my stuff in a container locally, it's not too far off from I feel it's viable to move everything to a computer in the cloud. Our DS people are working like that already, with their notebooks and stuff.
You just never have local copies of anything. Everything just runs on a server from your thin client.
Even useful if you need extra horsepower for a Language Server.
So, you see result, as you type.
I don't understand the in-browser code editor experience. How does it work?
I tried the emacs keybindings on replit... what a joke - Control-N to go to the next line? Nope. Control-P for previous? Nope. Meta-F? opens the file menu. I don't even know what keybindings I should be hoping will work.
Vi keybindings are much more usable in-browser (obviously).
A massive problem for me was getting out of the frame and not being able to get back in. I wanted to do something like ":compile". Or ":n" to get to the next focusable input field.
Maybe there are function keys bound? I wish I could find out.
Is there any possibility of one of these "IDEs" having auto-indent / reindent? I see from the docs there's supposed to be one, but all I get is not-smart left/right motion.
Working with beginners it would be very nice.
> How does it work?
It's a web application, so a lot of JavaScript.
> I tried the emacs keybindings on replit... what a joke
It needs some more love, the work is done out in the open, feel free to open issues. https://github.com/replit/codemirror-emacs
For what it's worth, we're not trying to recreate your emacs or VIM experience, just trying to port as many keybindings as we can. Will log the things you mentioned, it just seems like there's conflict with other keybindings.
> Maybe there are function keys bound? I wish I could find out.
Ctrl+Enter to run
> Is there any possibility of one of these "IDEs" having auto-indent / reindent? I see from the docs there's supposed to be one, but all I get is not-smart left/right motion.
What do you mean by left/right motion? Are you asking for like an auto-format feature? Or just handle re-indent when the indentation options change?
* From article: “CodeMirror would achieve that by leaning on native browser text editing (via contentEditable) rather than implementing text editing entirely in the library/javascript.”.
Edit: from https://blog.replit.com/codemirror “CodeMirror 6 is a complete rewrite of the CodeMirror editor with a focus on accessibility, touchscreen support, and extensibility.”. I expect that marjin really cares about accessibility. However, in my limited experience, as a lone developer I couldn’t make our complex product properly accessible unless that was the focus of say six months effort, which we couldn’t afford at the time.
Sure, I understand that people don't have infinite time to spend on perfect accessibility. I was careful not to have any blaming tone in my message.
The vast majority of the world uses a mobile phone to connect to the internet. While I do agree that web-based editors aren't as good as desktop-based editors, and that there's potential for abuse in the transactional nature of web-based editors, a web-based editor is the best that billions of people can manage.
It's not perfect, but I'd take a world with online code editors over a world where coding is only possible in a desktop environment. A world with more programmers and more people who are knowledgeable about how their digital lives really work is better than a world with fewer in the know, or fewer who are empowered to know due to technological limitations.
But I agree, I will still never leave Emacs :) though, I don't think this project is aimed at replacing standalone editors.
Just for that fact I've been implementing CodeMirror in every project I need to.
One of them the uses was for the Remote Editor of my programming environment for Android, PHONK https://github.com/victordiaz/PHONK (is unmantained nowadays because of lack of time).
What I loved the most was the API to tweak the editor the way you want. Ace come with a demo where you can tweak all parameters easily. The only bug I encountered back in the day was some scrolling issues with ipads but probably is solved already.
I tried also CodeMirror and Monaco but somehow went back to Ace because of its simple setup.
For editors in general, CodeMirror 6 is an excellent, modular rewrite of CodeMirror 5.
Monaco uses it's own build system that requires a lot of configuration twiddling to get it to work. Powerful, but it's first and foremost built for VSCode.
Great blogpost.
IT has the final word on what development servers look like, what tools are allowed and what devs are able to do.
Remote development servers are the IT dream on devs not screwing up devenvs, or sneak in unallowed tooling.