lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250703173848.721de72c@sal.lan>
Date: Thu, 3 Jul 2025 17:38:48 +0200
From: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>
To: Jonathan Corbet <corbet@....net>
Cc: linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org, Akira Yokosawa
 <akiyks@...il.com>
Subject: Re: [PATCH 2/7] docs: kdoc: micro-optimize KernRe

Em Tue,  1 Jul 2025 14:57:25 -0600
Jonathan Corbet <corbet@....net> escreveu:

> Switch KernRe::add_regex() to a try..except block to avoid looking up each
> regex twice.
> 
> Signed-off-by: Jonathan Corbet <corbet@....net>
> ---
>  scripts/lib/kdoc/kdoc_re.py | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/lib/kdoc/kdoc_re.py b/scripts/lib/kdoc/kdoc_re.py
> index e81695b273bf..a467cd2f160b 100644
> --- a/scripts/lib/kdoc/kdoc_re.py
> +++ b/scripts/lib/kdoc/kdoc_re.py
> @@ -29,12 +29,10 @@ class KernRe:
>          """
>          Adds a new regex or re-use it from the cache.
>          """
> -
> -        if string in re_cache:
> +        try:
>              self.regex = re_cache[string]
> -        else:
> +        except KeyError:
>              self.regex = re.compile(string, flags=flags)
> -

Hmm... I opted for this particular way of checking is that I
expect that check inside a hash at dict would be faster than
letting it crash then raise an exception. 

Btw, one easy way to check how much it affects performance
(if any) would be to run it in "rogue" mode with:

	$ time ./scripts/kernel-doc.py -N .

This will run kernel-doc.py for all files at the entire Kernel
tree, only reporting problems. If you want to do changes like
this that might introduce performance regressions, I suggest
running it once, just to fill disk caches, and then run it
again before/after such changes.

Anyway, I did such measurements before/after your patch.
the difference was not relevant: just one second of difference:

original code:

real	1m20,839s
user	1m19,594s
sys	0m0,998s

after your change:

real	1m21,805s
user	1m20,612s
sys	0m0,929s

I don't mind myself to be one second slower, but this is hardly
a micro-optimization ;-)

-

Disclaimer notice: one second of difference here can be due to
some other background process on this laptop.

Regards,
Mauro

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ