GNU bug report logs - #47712
27.1; Provide `string-display-width` function, which takes properties into account, `substring-width`

Previous Next

Package: emacs;

Reported by: Daniel Mendler <mail <at> daniel-mendler.de>

Date: Sun, 11 Apr 2021 21:17:02 UTC

Severity: normal

Found in version 27.1

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #50 received at 47712 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Daniel Mendler <mail <at> daniel-mendler.de>
Cc: 47712 <at> debbugs.gnu.org
Subject: Re: bug#47712: 27.1; Provide `string-display-width` function, which
 takes properties into account, `substring-width`
Date: Mon, 12 Apr 2021 20:01:53 +0300
> Cc: 47712 <at> debbugs.gnu.org
> From: Daniel Mendler <mail <at> daniel-mendler.de>
> Date: Mon, 12 Apr 2021 16:38:08 +0200
> 
> On 4/12/21 4:32 PM, Eli Zaretskii wrote:
> > My benchmarking indicates that reusing the buffer makes
> > string-pixel-width only 10 times slower than string-width, i.e. 50
> > about microseconds per call.
> 
> Can you please paste the exact code you used? As I wrote in my previous 
> mail, I tried without buffer switching, but it was still 50 times 
> slower.

  (defun string-pixel-width (string)
    (with-current-buffer (get-buffer-create "foo")
      (erase-buffer)
      (insert string)
      (window-text-pixel-size nil (point-min) (point-max))))

  (defvar test-string
     (concat "some string with "
	     (propertize "invisible substring" 'invisible t)
	     " and "
	     (propertize "a displayed substring"
			 'display "an overwritten substring")))

  (benchmark-run 100000 (string-pixel-width test-string))
  (benchmark-run 100000 (string-width test-string))

> 10 times slower is still not good, but given that number I may 
> stop arguing, since the factor will be even less in real code.

You can still use your code in org-table, if it does the job, I just
don't think we should have a semi-working API in core.

(There's indeed something strange with the results, I think the
with-current-buffer thing is not enough (because if I manually switch
to buffer "foo" and run the function, it returns correct results).  I
will take a closer look when I have time, unless martin beats me to
it.)




This bug report was last modified 4 years and 37 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.