From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Jonathan Corbet <corbet@lwn.net>
Cc: Linux Doc Mailing List <linux-doc@vger.kernel.org>,
Kees Cook <kees@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] docs: Sphinx: kerneldoc: only initialize kernel-doc classes once
Date: Fri, 25 Apr 2025 15:29:23 +0800 [thread overview]
Message-ID: <20250425152923.760e22e6@sal.lan> (raw)
In-Reply-To: <b00788f26e161512858a6e01a673c34743c954df.1745564565.git.mchehab+huawei@kernel.org>
Hi Jon,
Em Fri, 25 Apr 2025 15:13:38 +0800
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> escreveu:
> Instead of re-creating the objects every time, initialize it
> just once.
>
> This allows caching previously parsed objects.
Please notice that I opted to send you this one as you mentioned that
performance decrease when using classes.
While this patch is simple, it does improve performance and on my tests
it is working fine, it has a potential of causing troubles. So, maybe
it could be wise to keep this on tests for a while - eventually
postponing this one to be applied after the merge window.
Patches 2 and 3 on this series should be OK to be merged, as they
are mainly cleanups.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
> Documentation/sphinx/kerneldoc.py | 23 +++++++++++------------
> 1 file changed, 11 insertions(+), 12 deletions(-)
>
> diff --git a/Documentation/sphinx/kerneldoc.py b/Documentation/sphinx/kerneldoc.py
> index 27baf28fb754..b713a2c4a615 100644
> --- a/Documentation/sphinx/kerneldoc.py
> +++ b/Documentation/sphinx/kerneldoc.py
> @@ -48,7 +48,8 @@ from kdoc_files import KernelFiles
> from kdoc_output import RestFormat
>
> __version__ = '1.0'
> -use_kfiles = False
> +kfiles = None
> +logger = logging.getLogger('kerneldoc')
>
> def cmd_str(cmd):
> """
> @@ -86,7 +87,6 @@ class KernelDocDirective(Directive):
> 'functions': directives.unchanged,
> }
> has_content = False
> - logger = logging.getLogger('kerneldoc')
> verbose = 0
>
> parse_args = {}
> @@ -204,7 +204,7 @@ class KernelDocDirective(Directive):
> node = nodes.section()
>
> try:
> - self.logger.verbose("calling kernel-doc '%s'" % (" ".join(cmd)))
> + logger.verbose("calling kernel-doc '%s'" % (" ".join(cmd)))
>
> p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
> out, err = p.communicate()
> @@ -214,14 +214,14 @@ class KernelDocDirective(Directive):
> if p.returncode != 0:
> sys.stderr.write(err)
>
> - self.logger.warning("kernel-doc '%s' failed with return code %d"
> + logger.warning("kernel-doc '%s' failed with return code %d"
> % (" ".join(cmd), p.returncode))
> return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))]
> elif env.config.kerneldoc_verbosity > 0:
> sys.stderr.write(err)
>
> except Exception as e: # pylint: disable=W0703
> - self.logger.warning("kernel-doc '%s' processing failed with: %s" %
> + logger.warning("kernel-doc '%s' processing failed with: %s" %
> (" ".join(cmd), str(e)))
> return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))]
>
> @@ -261,7 +261,7 @@ class KernelDocDirective(Directive):
> self.do_parse(result, node)
>
> except Exception as e: # pylint: disable=W0703
> - self.logger.warning("kernel-doc '%s' processing failed with: %s" %
> + logger.warning("kernel-doc '%s' processing failed with: %s" %
> (cmd_str(cmd), str(e)))
> return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))]
>
> @@ -292,11 +292,9 @@ class KernelDocDirective(Directive):
> return node.children
>
> def run(self):
> - global use_kfiles
> + global kfiles
>
> - if use_kfiles:
> - out_style = RestFormat()
> - kfiles = KernelFiles(out_style=out_style, logger=self.logger)
> + if kfiles:
> return self.run_kdoc(kfiles)
> else:
> return self.run_cmd()
> @@ -306,13 +304,14 @@ class KernelDocDirective(Directive):
> self.state.nested_parse(result, 0, node, match_titles=1)
>
> def setup_kfiles(app):
> - global use_kfiles
> + global kfiles
>
> kerneldoc_bin = app.env.config.kerneldoc_bin
>
> if kerneldoc_bin and kerneldoc_bin.endswith("kernel-doc.py"):
> print("Using Python kernel-doc")
> - use_kfiles = True
> + out_style = RestFormat()
> + kfiles = KernelFiles(out_style=out_style, logger=logger)
> else:
> print(f"Using {kerneldoc_bin}")
>
next prev parent reply other threads:[~2025-04-25 7:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-25 7:13 [PATCH 0/3] Some small improvements for kernel-doc generation Mauro Carvalho Chehab
2025-04-25 7:13 ` [PATCH 1/3] docs: Sphinx: kerneldoc: only initialize kernel-doc classes once Mauro Carvalho Chehab
2025-04-25 7:29 ` Mauro Carvalho Chehab [this message]
2025-04-25 7:13 ` [PATCH 2/3] scripts/lib/kdoc: change mode to 0644 Mauro Carvalho Chehab
2025-04-25 7:13 ` [PATCH 3/3] scripts/lib/kdoc/kdoc_parser.py: move kernel entry to a class Mauro Carvalho Chehab
2025-04-28 23:34 ` [PATCH 0/3] Some small improvements for kernel-doc generation Jonathan Corbet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250425152923.760e22e6@sal.lan \
--to=mchehab+huawei@kernel.org \
--cc=corbet@lwn.net \
--cc=kees@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).