zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
47.17k stars 2.72k forks source link

Pasting text is sometimes absurdly slow #4695

Open jansol opened 1 year ago

jansol commented 1 year ago

Check for existing issues

Describe the bug / provide steps to reproduce it

Copying this short text snippet and pasting it into Zed makes the editor freeze for around 10 seconds.

          ╎┆┊  ╱🭽▔🭾╲    🮲🮳       🮸🮀🮵🮶🮀🮁🮁🮀🮼🯁🯂🯃      ▵        ↑        ◬
 ╶─╴╺━╸ ═ ╎┆┊ ⎹ ⎸▣⎹ ⎸  ▝▛▀▜▘ 🯲🯷🯶                   △    ▴   ╽       ◭⬘◮
╷┌┬┐┍┯┑╒╤╕╏┇┋ 🮷 🭼▁🭿 ⎸  ▚▌█▐▞ 🯹🯵🯱 🯰     ▁▂▃▄▅▆▇█ ◃◅◁╳▷▻▹ ▲ ←╼╋╾→     ◩⬒⬔
│├┼┤┝┿┥╞╪╡╏┇┋ ⎹╱ ╳ ╲⎸  ▗▙▄▟▖ 🯴🯳🯸      █🮆🮅🮄▀🮃🮂▔⎹    ▽ ◂◄◀🮽▶►▸╿  ⮝   ⬖◧◫◨⬗
╵└┴┘┕┷┙╘╧╛┞╀┦  ▔▔▔▔▔   🬑🬜🬰🬪🬟      🮞🮟 ▕▉ ◞◡◯◡ ◎🭵    ▿    ▼   ↓ ⮜◈⮞   ⬕⬓◪  
╻┎┰┒┏┳┓  ┭╆╈╅┮╍╍╌╌  🬥🬦🬍🬲🬵🬹🬱🬷🬌🬓🬙   🮝🮜 🮇▊◝◠◯◉◯◡◟🭴         ▾      ⮟   ◕ ⬙ ◔
┃┠╂┨┣╋┫ ╺┽╊◙╉┾┅┅┄┄  🬔🬡🬖🬻🬞🬭🬏🬺🬢🬒🬧      🮈▋◍ ◠◯◠◜ 🭳  ◿◺                     
╹┖┸┚┗┻┛ ━┵╄╇╃┶┉┉┈┈  🬃🬤🬫🬴🬠🬋🬐🬸🬛🬗🬇   🭇🬼 ▐▌ ◌🮣🮢 🮦 🭲  ◹◸ 🭯 🮀⚞⚟🮀  🯊     ◙◛◶─◵
 ╓╥╖   ╔╦╗┢╁┪ ┟┱┲┧  🬣🬯🬈🬬🬁🬂🬀🬝🬅🬮🬘   🭢🭗 🮉▍ 🮤🮪🮫🮥🮧 🭱  🭯 🭮◙🭬╭──╮⎫🮻⎧    ◘◙│◲┼◱╭◒╮
║╟╫╢🮐🮒🮐╠╬╣ ╹┃ ┡┹┺┩  🬳🬉🬩🬕🬊🬎🬆🬨🬚🬄🬶   🭊🬿 🮊▎ 🮩🮬🮭🮨  🭰 ◢🭫◣ 🮚 │ ▢ ⎮🏎⎪    ◙◚◷┼◴│◑╋◐
 ╙╨╜🮔 🮓╚╩╝   🯆 🯅  🯇     🮣🮢   🯉  🯈 🭥🭚 🮋▏🮮 🮡🮠   ⎸🭮🭪◆🭨🮛🮿🭬╰─🮯─╯⎬⎯⎨       ◳─◰╰◓╯    
  ░░🮐🮑🮐▓▓██🮗🮗▤▤▥▥▦▦▩▩▧▧🮘🮘🮙🮙▨▨🮕🮕🮖🮖 🭋🭀 █▁🭻🭺🭹🭸🭷🭶▔  ◥🭩◤ 🭭      ⎮⯊⎪ ▱▰    ▭▬
  ░░▒🮎▒▓▓██🮗🮗▤▤▥▥▦▦▩▩▧▧🮘🮘🮙🮙▨▨🮕🮕🮖🮖 🭦🭛         🮰 🭇🬼🭭 🭊🬿 🭋🭀   ⎭⯋⎩ ▯▮  ▫◻□■◼▪⬝·
    🮌█🮍                 ╲╱  🭇🬼🭈🬽🭉🬾◢◣🭇🭃🭎🬼🭈🭆🭂🭍🭑🬽🭉🭁🭌🬾🭈🭄🭏🬽🭅🭐 ◦○◯⬤◖◗ ⬫⬦⬨♢◊◇◆♦⬧⬥⬩⬪
    ▒🮏▒                     🭢🭗🭣🭘🭤🭙◥◤🭢🭔🭟🭗🭣🭧🭓🭞🭜🭘🭤🭒🭝🭙🭣🭕🭠🭘🭖🭡  ∘⭘●          
                                               🭢🭗  🭥🭚 🭦🭛    •

(source: unicode graphics character test image from http://viznut.fi/unscii/ )

After deleting the text, pasting it in again is instantaneous as expected.

This is surprising, as it is not really a lot of text and taking e.g. a long run of Chinese text and pasting it is nearly instant even when no CJK characters were originally present in any file that is open in the current Zed instance (and thus not cached).

FWIW pasting the snippet into this issue in Firefox was also clearly slow, but nowhere near 10 seconds.

Environment

Zed: v0.90.1 (stable) OS: macOS 12.6.6 Memory: 16 GiB Architecture: x86_64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

If you only need the most recent lines, you can run the zed: open log command palette action to see the last 1000.

No response

maxbrunsfeld commented 1 year ago

I can't reproduce this. Does it reliably happen for you, even in a new untitled buffer? If not, can you provide more detailed steps that reproduce the problem? What font and settings are you using? Do you have any custom fonts installed on your system that might be getting used in font fallback?

ForLoveOfCats commented 1 year ago

Can you also let us know if repeated pastes after the initial paste are just as slow?

jansol commented 1 year ago

Happens reliably in a new untitled buffer in a new project. Pasting the text again is instantaneous until I completely quit Zed and relaunch it, at which point the first time pasting the snippet is slow again (both in untitled tabs and in existing files where I tried).

My config.json:

{
  "theme": "Summercamp",
  "buffer_font_family": "IntelOne Mono",
  "buffer_font_size": 11,
  "buffer_font_features": {
    "calt": true // contextual alternatives e.g. !=
  },
  "features": {
    "copilot": false
  },
  "show_whitespaces": "all",
  "journal": {
    "path": "~",
    "hour_format": "hour24"
  },
  "format_on_save": "off",
  "terminal": {
    "dock": "right",
    "option_as_meta": true,
    "line_height": "standard"
  }
}

IntelOne Mono only contains basic ASCII characters (+accents) so a fallback font is definitely being used here. FWIW Firefox shows a whole bunch of fonts being used for the snippet here on this page:

image
maxbrunsfeld commented 1 year ago

Thanks so much for the follow-up. I would be curious if one or more of those fonts is responsible for the slowdown. This may be tedious, but if you have time to investigate, could you try uninstalling Agave Nerd Font, or unscii, to see if those fonts are the cause?

Maybe there is something about our font loading that is inefficient.

jansol commented 1 year ago

Neither disabling those two fonts via Font Book nor uninstalling them made a difference.

maxbrunsfeld commented 1 year ago

Oh, I didn't notice a third custom font in there: STIXGeneral. I wonder if it's that, or just IntelMono itself.

jansol commented 1 year ago

I don't think I can delete /System/Library/Fonts/Supplemental/STIXGeneral.otf to test... However if I simply switch the editor font to Zed Mono, pasting is instant.

I remember reading that Zed Mono is based on Iosevka so I tried setting that as the editor font and... pasting the snippet is instant, HOWEVER upon saving the config I got greeted with a 10s beach ball. And launching Zed with Iosevka set as the editor font shows that the process launches, but there is a 10s delay before the window gets opened. (IntelOne does not cause a delay when launching Zed)

JosephTLyons commented 1 month ago

Is this still true for you in current Zed, @jansol? I wasn't able to reproduce it myself in v0.147.0.

jansol commented 1 month ago

Still happens in 0.146.1, if I have Iosevka installed (not even specified in Zed's config), pasting the test pattern for the first time after launching Zed beachballs for several seconds. With Iosevka removed it takes a whole second but no beachball (cursor briefly reverts from I-beam to default though). Subsequent pastes are instant in both cases.