[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#48734: 28.0.50; Performance regression in `string-width`?
From: |
Eli Zaretskii |
Subject: |
bug#48734: 28.0.50; Performance regression in `string-width`? |
Date: |
Sun, 30 May 2021 09:42:29 +0300 |
> From: Imran Khan <contact@imrankhan.live>
> Date: Sun, 30 May 2021 02:45:57 +0600
>
> A package I use (deft-mode) has been hanging for minutes with high cpu
> use recently. Profiler says most time is spent in `string-width`, and
> upon looking it seems to happen in files that have multibyte characters
> in them.
>
> I reproduced the problem by creating a file that has both single and
> multi byte characters:
>
> with open("/tmp/test", "w") as f:
> for i in range(50_000):
> print("1", file=f, end="")
> print("α", file=f, end="")
>
> And now:
>
> (benchmark-run 1
> (let ((str))
> (with-temp-buffer
> (insert-file-contents-literally "/tmp/test")
> (setq str (buffer-string)))
> (string-width str)))
>
> This takes 20 seconds in my machine (if string is exclusively full of
> either single or multibyte characters, weirdly it seems to finish
> instantly).
Since you use insert-file-contents-literally, why don't you also make
the temporary buffer unibyte? That is:
(benchmark-run 1
(let ((str))
(with-temp-buffer
(set-buffer-multibyte nil) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
(insert-file-contents-literally "/tmp/test")
(setq str (buffer-string)))
(string-width str)))
Or maybe I don't understand your real-life use case? Because if you
treat the file as a raw bytestream, why do you need to compute the
width of its text?
- bug#48734: 28.0.50; Performance regression in `string-width`?, Imran Khan, 2021/05/29
- bug#48734: 28.0.50; Performance regression in `string-width`?,
Eli Zaretskii <=
- Message not available
- bug#48734: 28.0.50; Performance regression in `string-width`?, Eli Zaretskii, 2021/05/30
- bug#48734: 28.0.50; Performance regression in `string-width`?, Imran Khan, 2021/05/30
- bug#48734: 28.0.50; Performance regression in `string-width`?, Eli Zaretskii, 2021/05/30
- bug#48734: 28.0.50; Performance regression in `string-width`?, Lars Ingebrigtsen, 2021/05/30
- bug#48734: 28.0.50; Performance regression in `string-width`?, Eli Zaretskii, 2021/05/30
- bug#48734: 28.0.50; Performance regression in `string-width`?, Lars Ingebrigtsen, 2021/05/31
- bug#48734: 28.0.50; Performance regression in `string-width`?, Imran Khan, 2021/05/31
- bug#48734: 28.0.50; Performance regression in `string-width`?, Eli Zaretskii, 2021/05/31
- bug#48734: 28.0.50; Performance regression in `string-width`?, Eli Zaretskii, 2021/05/31