# gpui_linux: Fix unbounded memory growth when composing text with Fcitx5 under KWin/Wayland \(\#61079\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/5079b33d657593ffd8a2d2978534988a8b40867e)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 5079b33d657593ffd8a2d2978534988a8b40867e

Requested commit: 5079b33d657593ffd8a2d2978534988a8b40867e

Commit: 5079b33d657593ffd8a2d2978534988a8b40867e

Tree: 279839fc157ba989b62d5084a5bcbbf56b79d344

Author: ᴀᴍᴛᴏᴀᴇʀ

Committer: GitHub

## Message

```
gpui_linux: Fix unbounded memory growth when composing text with Fcitx5 under KWin/Wayland (#61079)

# Objective

Close #61034.

Fix unbounded memory growth when composing text with Fcitx5 under
KWin/Wayland.

While a non-empty preedit is cached, KWin resends it whenever it
receives a text-input-v3 `commit()` ([relevant KWin
code](https://github.com/KDE/kwin/blob/0e473e87a64d5d404c2fecf5516a9a5c3cf17d91/src/wayland/textinput_v3.cpp#L444-L504)).

Zed handles the replayed preedit as a buffer edit. This invalidates the
IME character coordinates, causing Zed to submit the same cursor
rectangle and call `commit()` on the next frame. That commit makes KWin
replay the cached preedit again, forming an infinite feedback loop.

The observed memory growth is caused by retained CRDT state accumulating
indefinitely.

## Solution

Following [SDL's solution to the same
problem](https://github.com/libsdl-org/SDL/commit/81479d8784d0e1a61eafb3a444dd3865ad762fb2),
cache the last submitted cursor rectangle and compare it with the new
rectangle before calling `set_cursor_rectangle()`.

If the rectangles are equal, skip both the rectangle update and its
associated `commit()`. The initial cursor rectangle and actual rectangle
changes during an active composition are still submitted, preserving the
candidate-window positioning behavior introduced by #59911.

## Testing

Manually tested on KDE Plasma with `fcitx5-chinese-addons`. 

Before the fix, memory usage grew continuously while preedit text was
present, with `WAYLAND_DEBUG=client` showing text-input events repeating
indefinitely.

After the fix, the repeated events stopped and memory usage remained
stable.

No automated test was added because reproducing the feedback loop
requires compositor-specific KWin text-input-v3 behavior.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable


---

Release Notes:

- Fixed excessive memory usage when composing text with Fcitx5 on KDE
Wayland.

---------

Co-authored-by: Tom Houlé <tom@tomhoule.com>
```

## Parents

- [1d2a4b3f7f194184dccadfa7a091d16a06482752](https://git.cafe/gitcafe/zed/commit/1d2a4b3f7f194184dccadfa7a091d16a06482752?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/5079b33d657593ffd8a2d2978534988a8b40867e?format=markdown)
