DEV Community

Cover image for 117 ms vs 908 ms: Timing My Text Editor Against Windows Notepad
HideyukiMORI
HideyukiMORI

Posted on Edited on

117 ms vs 908 ms: Timing My Text Editor Against Windows Notepad

My text editor shows a 16 MiB file in 117 ms. Windows Notepad takes 908 ms on the same machine.

Both numbers are medians of 20 runs, measured the same way from outside the apps. I also timed Sakura Editor, a long-standing Windows editor that's popular in Japan.

What's in this post:

  • How I timed three editors without trusting any app's own clock
  • The numbers, including the ones where Nib loses
  • Four things Nib does to open a 16 MiB file fast

The setup

NeNe Nib is my text editor for Windows 11. It works like Notepad by default, and Ctrl+Shift+Space switches it to Vim editing. I wrote about what it does and how its first frame appears in 41 ms earlier.

This time I wanted a number I could compare with other editors. The app's internal timer can't do that, because every app starts and stops its own clock in a different place.

How I measured it

I timed what you actually see:

  1. Just before the action, turn a marker on the screen white.
  2. Record the screen at 60 fps.
  3. Count frames from the white marker to the frame where text appears inside the app's window.

One frame is about 17 ms, so that's the resolution. I rotated the order of the apps on every run and threw away the first run as a warm-up.

All runs used one PC: Windows 11 Pro (build 26300), Core i9-10850K, RTX 3090, 3840×2160. Each app had default settings and the same 1584×892 client area. The files were UTF-8 .txt files with LF line endings and some Japanese text, and they were already in the OS file cache.

For memory, I read PrivateWorkingSetSize from GetProcessMemoryInfo after the app settled. That's RAM actually in use, without GPU or shared memory.

The numbers

Medians of 20 runs for time and 10 runs for memory. Bold is the best of the three.

NeNe Nib 1.1.0 Sakura Editor 2.4.3 Notepad 11.2609
Launch with 200 lines, until text appears 100 ms 267 ms 450 ms
Launch with 16 MiB, until text appears 117 ms 383 ms 908 ms
RAM after opening 200 lines 14.1 MiB 11.6 MiB 40.4 MiB
RAM after opening 16 MiB 30.4 MiB 54.2 MiB 88.7 MiB
Package size 4.75 MB 5.62 MB 18.55 MB

Against Notepad, that's about 4.5x faster with the small file and 7.8x faster with the 16 MiB file.

Nib doesn't win everything:

  • With a small file, Sakura Editor uses less RAM.
  • Sakura Editor's package is 3.61 MB without its help files, which is smaller than Nib.
  • Both Sakura Editor (2.26 MB) and Notepad (3.21 MB) have smaller executables than Nib (4.57 MB). Notepad's package size doesn't include the Windows App Runtime and VCLibs it needs.

What Nib does to open 16 MiB in 117 ms

Nib doesn't show part of the file first. For files up to 64 MiB, it reads the whole file and builds its line index before the text appears.

So the speed has to come from doing less work per byte.

1. The bytes are never copied

The bytes read from disk go through encoding detection and become the document's text without a copy.

They travel in a move-only type, SealedBytes, so nothing can change them on the way. In the prototype, building the document from a 16 MiB file dropped from 11.3 ms to 8.3 ms.

A UTF-8 BOM isn't erased either. Nib starts the text 3 bytes later instead of moving the whole file in memory.

2. The text is a piece table

The file stays in one buffer, and typed text goes into another. Right after opening, the document is a single piece: "the whole file buffer."

Nothing gets rearranged when a file opens.

3. The line index uses one bit per byte

To find where a line starts, Nib keeps an index of line breaks. It splits the text into 64 KiB chunks, and each chunk uses one of two forms:

  • Few line breaks: a list of 16-bit positions
  • Many line breaks: one bit per byte, plus a running count every 512 bytes

With the bit form, counting the line breaks before any position takes one stored count and a popcount over at most 8 words. Nib never rereads the text to find a line.

4. It draws only the visible lines

Only the lines in the window are drawn. The conversion to UTF-16 for DirectWrite happens only for those lines, only when they're drawn.

A 16 MiB file still needs only a few dozen lines of work to reach the screen.

What I haven't measured

  • Other PCs, and GPUs other than NVIDIA
  • Files that aren't in the OS file cache
  • Keystroke latency (this method couldn't produce usable data)
  • Nib with the language server or minimap turned on
  • Launching from the Microsoft Store icon instead of the executable

The short video shows 133 ms vs 983 ms. Those came from the recorded takes (median of 5), and recording adds load, so they're higher than the table.

Sources

Try it

Get NeNe Nib on the Microsoft Store (free)

If you run the same kind of test on your own PC, I'd like to see the numbers. How do you measure how fast an app feels?

Top comments (2)

Collapse
 
userxnom profile image
Abdullah Naseer •

The measurement method is what makes the numbers believable — counting 60 fps frames from a white marker instead of trusting each app's own clock, and rotating the run order, removes the two easiest ways to fool yourself. The piece-table plus one-bit-per-byte line index is a neat pairing too: the file never gets rearranged on open, and finding a line costs a stored count plus a popcount instead of a rescan. I also appreciate the 'doesn't win everything' section — Sakura on RAM and package size keeps the comparison honest.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

Frame counts from a white marker beat an app's own clock. Its own clock would just tell you what it wants to hear.