Repository navigation
markdown: Fix crashes on tab-indented code blocks - #65398
Conversation
Key cached highlights by typed event indices instead of source offsets, which can collide during tab expansion. Add a layout regression test covering the crash and related edge cases.
c31847b to
f321107
Compare
MrSubidubi
left a comment
There was a problem hiding this comment.
Looking at this, I am almost curious why we do not cache based on text content and rather on event index - the latter I consider infinitely more unstable than the former in a lot of cases. Curious whether I am just missing something? Does highlight_text_resolved not already key by content? What exactly does the cache here add us atop of the existing text highlights cache? Merely curious.
Similarly, took another look just now and noticed that highlight_text_resolved takes a rope by ref - I checked and while this would reach pretty deep, I have the feeling that we could at this stage maybe support passsing in anther trait where the trait requires implementation of textprovider? We currently implement that only for ropes, yet if we were to add this (probably not here though), we could save a ton of large string allocations for cases like this one here perhaps? As we convert the str to a rope, then pass by ref, then potentially again create an entire string from it - that seems wasteful.
Not insisting, maybe something better suited for its own PR to be merged post Wednesday :)
|
Currently, the map is not reused across parses, so it does not need to survive edits — hence it's an ok fix to key by such "unstable" key. The allocations is definitely a great point, but not related to the crash per se, and is, indeed, quite a large change, fine to do a follow-up later. Not sure I follow what's blocking this PR though, given the first paragraph is the curiosity and the other one is postponed? |
MrSubidubi
left a comment
There was a problem hiding this comment.
Nothing blocking post the clarification around parsing, forgot we clear this during parse events.
That said, I'd be interested in how many cache hits we have in the underlying cache on the language level, given that we are also caching there based on the content (and that should survive reparsing if I am not mistaken/missing something obvious in
zed/crates/language/src/language.rs
Lines 1133 to 1140 in 1c9dd3e
Another save for allocations - I suppose we could newtype the runs returned by that method and then get rid of the to_vec there in that method by just returning the wrapped arc and probably deriving deref on that.
|
Yeah, we sure have the test for the reparsing survival, |
|
/cherry-pick preview |
|
🍒💥 Cherry-pick did not succeed |
…ck to preview) (#65406) Cherry-pick of #65398 to preview ---- Fixes #65320 Key cached highlights by typed event indices instead of source offsets, which can collide during tab expansion. Add a layout regression test covering the crash and related edge cases. Release Notes: - Fixed crashes on tab-indented code blocks Co-authored-by: Kirill Bulatov <kirill@zed.dev>
|
I think I've captured most of the advice into a normal form here: #65409 |
Follow-up to zed-industries#65398 (review) Not implemented from the feedback: - Returning the cached `Arc` runs from `highlight_text` behind a newtype: read-only callers now use `highlight_text_resolved(..).runs` directly, while `CodeLabel` callers still need an owned `Vec`, which `highlight_text` now collects once. - Caching the `Rope` itself to avoid the copy on a cache miss: this needs a new rope-to-rope comparison and roughly doubles the memory each entry retains, so the cache keeps one `String` copy. Release Notes: - N/A
Follow-up to zed-industries#65398 (review) Not implemented from the feedback: - Returning the cached `Arc` runs from `highlight_text` behind a newtype: read-only callers now use `highlight_text_resolved(..).runs` directly, while `CodeLabel` callers still need an owned `Vec`, which `highlight_text` now collects once. - Caching the `Rope` itself to avoid the copy on a cache miss: this needs a new rope-to-rope comparison and roughly doubles the memory each entry retains, so the cache keeps one `String` copy. Release Notes: - N/A
Follow-up to zed-industries/zed#65398 (review) Not implemented from the feedback: - Returning the cached `Arc` runs from `highlight_text` behind a newtype: read-only callers now use `highlight_text_resolved(..).runs` directly, while `CodeLabel` callers still need an owned `Vec`, which `highlight_text` now collects once. - Caching the `Rope` itself to avoid the copy on a cache miss: this needs a new rope-to-rope comparison and roughly doubles the memory each entry retains, so the cache keeps one `String` copy. Release Notes: - N/A (cherry picked from commit 7fa2adbe088c8feb3173aec4fc5f8ac0fc153f31)
Fixes zed-industries#65320 Key cached highlights by typed event indices instead of source offsets, which can collide during tab expansion. Add a layout regression test covering the crash and related edge cases. Release Notes: - Fixed crashes on tab-indented code blocks
Fixes #65320
Key cached highlights by typed event indices instead of source offsets, which can collide during tab expansion. Add a layout regression test covering the crash and related edge cases.
Release Notes: