unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] Fix a hash lookup problem in xfaces.c
@ 2022-01-01  9:24 Zhehao Lin
  2022-01-01  9:59 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Zhehao Lin @ 2022-01-01  9:24 UTC (permalink / raw)
  To: emacs-devel

Hello, this patch fixes a problem in the `face_for_font` function in `src/
xfaces.c` where an `unsigned` instead of an `uintptr_t` was used to 
store the
computed hash value of the face. If the hash value was too large (>UINT_MAX)
and truncated, the lookup and storing (the latter uses `uintptr_t` as 
the rest
of the program does) would happen in different buckets, resulting in 
constant
cache misses.

This can cause huge performance impact when `face_for_font' is called really
frequently (for example with ligatures enabled), but for brevity please 
allow
me to omit the details here.

Zhehao Lin


 From 06caba2dc34d8ffddd9917f0621d31317e899e90 Mon Sep 17 00:00:00 2001
From: Zhehao Lin <zh_lin1@outlook.com>
Date: Sat, 1 Jan 2022 16:19:49 +0800
Subject: [PATCH] * src/xfaces.c: Use uintptr_t instead of unsigned to store
  hash value

---
  src/xfaces.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/xfaces.c b/src/xfaces.c
index 6f52637e91..ae6143b330 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -4806,7 +4806,7 @@ face_for_font (struct frame *f, Lisp_Object 
font_object,
                 struct face *base_face)
  {
    struct face_cache *cache = FRAME_FACE_CACHE (f);
-  unsigned hash;
+  uintptr_t hash;
    int i;
    struct face *face;

-- 
2.34.1




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] Fix a hash lookup problem in xfaces.c
@ 2022-01-01  9:52 Zhehao Lin
  0 siblings, 0 replies; 3+ messages in thread
From: Zhehao Lin @ 2022-01-01  9:52 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 602 bytes --]

Hello, this patch fixes a problem in the `face_for_font` function in `src/
xfaces.c` where an `unsigned` instead of an `uintptr_t` was used to 
store the
computed hash value of the face. If the hash value was too large (>UINT_MAX)
and truncated, the lookup and storing (the latter uses `uintptr_t` as 
the rest
of the program does) would happen in different buckets, resulting in 
constant
cache misses.

This can cause huge performance impact when `face_for_font' is called really
frequently (for example with ligatures enabled), but for brevity please 
allow
me to omit the details here.

Zhehao Lin

[-- Attachment #2: 0001-src-xfaces.c-Use-uintptr_t-instead-of-unsigned-to-st.patch --]
[-- Type: text/x-patch, Size: 681 bytes --]

From 06caba2dc34d8ffddd9917f0621d31317e899e90 Mon Sep 17 00:00:00 2001
From: Zhehao Lin <zh_lin1@outlook.com>
Date: Sat, 1 Jan 2022 16:19:49 +0800
Subject: [PATCH] * src/xfaces.c: Use uintptr_t instead of unsigned to store
 hash value

---
 src/xfaces.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/xfaces.c b/src/xfaces.c
index 6f52637e91..ae6143b330 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -4806,7 +4806,7 @@ face_for_font (struct frame *f, Lisp_Object font_object,
                struct face *base_face)
 {
   struct face_cache *cache = FRAME_FACE_CACHE (f);
-  unsigned hash;
+  uintptr_t hash;
   int i;
   struct face *face;
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix a hash lookup problem in xfaces.c
  2022-01-01  9:24 Zhehao Lin
@ 2022-01-01  9:59 ` Eli Zaretskii
  0 siblings, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2022-01-01  9:59 UTC (permalink / raw)
  To: Zhehao Lin; +Cc: emacs-devel

> Date: Sat, 1 Jan 2022 17:24:27 +0800
> From: Zhehao Lin <zh_lin1@outlook.com>
> 
> Hello, this patch fixes a problem in the `face_for_font` function in `src/
> xfaces.c` where an `unsigned` instead of an `uintptr_t` was used to 
> store the
> computed hash value of the face. If the hash value was too large (>UINT_MAX)
> and truncated, the lookup and storing (the latter uses `uintptr_t` as 
> the rest
> of the program does) would happen in different buckets, resulting in 
> constant
> cache misses.

Thanks, installed on the emacs-28 branch.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-01  9:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-01  9:52 [PATCH] Fix a hash lookup problem in xfaces.c Zhehao Lin
  -- strict thread matches above, loose matches on Subject: below --
2022-01-01  9:24 Zhehao Lin
2022-01-01  9:59 ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).