Repository navigation
minimap - allow variable scaling - #82265
Conversation
This PR allows the minimap to be scaled to several constant values. Most of the work in this PR is adjusting the the font renderer to render character at variable sizes. It turns out most generic image scaling algorithms are not built to scale down to one or two pixels (the default minimap font size has 1px by 2px characters), so some work was needed to make this possible and look good. Generating fonts at runtime does incur a small performance penalty, taking about 0.6m at 1x scale and 0.9ms at 4x scale on my machine to create the font the first time we render a minimap. If we want to avoid this, we could consider shipping pre-rendered font for the first few scale settings. At this moment this only supports scaling to a constant integer--effectively, scaling the character width, since we start at 1x2px. More granular scaling would be interesting, but will come at a runtime cost as we'll need to do linear interpolation for each character we draw at a non-integral coordinate. Draw speed is comparable to the previous version, the profiler reported in the range of 8-11ms to render my test file in both the previous and new code. I've tested this on my high DPI Macbook display and it appears to work well there too. Talking to Alex, something we may need to look into is matching the user font and render settings. Previously, and continuing in this PR, we use the default monospace font on the system with a restricted set of character codes. Previously the sidebar's font was too small to be visible, but now its content can be seen under large settings. We may need to look and reworking how this data is rendered. Perhaps we generate the characters we need on the fly into their own buffers? Open to ideas. Fixes #21773
551bd19 to
928d48b
Compare
| renderMinimapCharRenderer(minimapCharRenderer1x, 400, 1); | ||
| renderMinimapCharRenderer(minimapCharRenderer2x, 500, 2); | ||
| renderMinimapCharRenderer(minimapCharRenderer4x, 600, 4); | ||
| renderMinimapCharRenderer(minimapCharRenderer6x, 750, 8); |
There was a problem hiding this comment.
Generating fonts at runtime does incur a small performance penalty, taking
about 0.6m at 1x scale and 0.9ms at 4x scale on my machine to create the font
the first time we render a minimap.
Shouldn't we only be rendering the scale we need and reacting when the scale setting or device pixel ratio changes?
There was a problem hiding this comment.
Additionally, this can vary wildly based on hardware and Chromium version based on my experience.
There was a problem hiding this comment.
Shouldn't we only be rendering the scale we need and reacting when the scale setting or device pixel ratio changes?
This is what we do! This file is a 'demo' page, previously used to generate the hardcoded image maps, and I put several more scales here now to assist with development. In the editor, the minimap calls MinimapCharRendererFactory.create(scale) when it resolves its rendering settings. The factory caches a singleton of the char renderer, so that it only creates one as needed (instead of rerendering the font for every minimap instance)
| ctx.fillStyle = '#ffffff'; | ||
| ctx.font = `bold ${Constants.SAMPLED_CHAR_HEIGHT}px monospace`; | ||
| ctx.textBaseline = 'middle'; | ||
| for (let chCode = Constants.START_CH_CODE; chCode <= Constants.END_CH_CODE; chCode++) { |
There was a problem hiding this comment.
This doesn't handle unicode or wide characters. Kind of feels like this is just leading to re-implementing xterm.js' texture atlas?
There was a problem hiding this comment.
Yea, this is something alexandrudima mentioned. Maybe the texture atlas in xterm could be popped into its own module that vscode can provide to and share between the minimap and xterm instances?
There was a problem hiding this comment.
Related existing issue that a user noticed on their high DPI display (where we used the 2x4px font) #64477
There was a problem hiding this comment.
👍 Really well done! I love the new down-sampling, the results are so much better!!:
So this PR fixes also #20929
| Before | After |
|---|---|
![]() |
![]() |
I am not super concerned with non-ASCII letters for this PR... since this is a minimap after all, and we can be imperfect in the name of speed... It's also an existing issue, so it is not introduced by this PR...
Some ideas to tackle letters outside the ASCII range:
- cheap way would be to render the famous unicode box for missing glyphs or switch to block rendering for lines which contain characters outside of the ASCII range.
- (more expensive) we could render them as space in the minimap imagedata and then have a post-process step on the
<canvas>where we invoke the canvas renderText on top of the places we skipped. - otherwise, perhaps an atlas of shapes, but that gets difficult very quickly (as Daniel Imms (@Tyriar) would know from xterm)
And a final idea:
- maybe it wouldn't be so bad to generate the minimap font based on the current configured font... Since with the scale: 8 we can really see it in detail. LMK if you need help figuring it out, the font info is also available as an editor option...
Good idea! Previously this wasn't possible but now that we're rendering at runtime it's pretty easy 🙂 In my next commit
This was straightfoward, so I've implemented this. The question box is, somewhat ironically, itself a double-width character, but it's legible at resolutions that text is, and it gets the message across and won't look out of place on most practical minimap scales. Thinking on it more overnight I'm inclined to agree with Alex regarding support for higher unicode characters. Unlike the terminal, where fonts need to be correct and beautifully rendered, the minimap is used to overview the shape of the code, and legibility is not a concern. As a user I'd put more weight on the minimap being lightweight and not impacting editor performance; the existing routines that we have that I've expanded on here are very fast, and increasing their correctness would likely involve a performance and complexity tradeoff. |
f8fe96f to
b48b016
Compare
Daniel Imms (Tyriar)
left a comment
There was a problem hiding this comment.
The question mark icon would be far better than what there was previously where is was just random ascii characters imo. The main concern around that is that you might get an increased number of reports about this as more users would be able to make out the differences.
|
We could limit the maximum minimap scale to be just below where text could be legible to avoid that. |
|
Can we select a different font for the minimap than is used in the main text area? Back in the day, I made a font called 2Small designed for legibility at extremely small sizes - each character being 5 pixels high. I'd like to try using it in the minimap but it's unsuitable in the main window. With ClearType, a horizontally condensed version of this font should remain legible in the minimap... |
|
Please open a new issue for that feature request! |




This PR allows the minimap to be scaled to several constant values. Most of the
work in this PR is adjusting the the font renderer to render character at
variable sizes. It turns out most generic image scaling algorithms are not
built to scale down to one or two pixels (the default minimap font size has
1px by 2px characters), so some work was needed to make this possible and look
good.
Generating fonts at runtime does incur a small performance penalty, taking
about 0.6m at 1x scale and 0.9ms at 4x scale on my machine to create the font
the first time we render a minimap. If we want to avoid this, we could consider
shipping pre-rendered font for the first few scale settings.
Draw speed is comparable to the previous version, the profiler reported in
the range of 8-11ms to render my test file in both the previous and new code.
I've tested this on my high DPI Macbook display and it appears to work well
there too.
Talking to Alex, something we may need to look into is matching the user font
and render settings. Previously, and continuing in this PR, we use the default
monospace font on the system with a restricted set of character codes.
Previously the sidebar's font was too small to be visible, but now its content
can be seen under large settings. We may need to look and reworking how this
data is rendered. Perhaps we generate the characters we need on the fly into
their own buffers? Open to ideas.
Fixes #21773