Re: [cocci] Cocci MUCH more slow after 6.11

Julia Lawall <[email protected]>
Newsgroups fr.inria.cocci
Message-ID <[email protected]>

On Tue, 16 Dec 2025, Ricardo Ribalda wrote:

> Hi Laura
>
> Has there been any progress on this?
>
> I am stuck with an old Debian version in our CI and I would like to
> update to debian stable.

Hello,

I made some improvements to the minmax semantic patch that made it go 4x
faster on my test machine.  Maybe it will help.

julia

>
> Regards!
>
> On Tue, 4 Feb 2025 at 16:10, Markus Elfring <[email protected]> wrote:
> >
> > …
> > > spatch version 1.1.1-00610-gd151c4895 compiled with OCaml version 4.13.1
> > …
> > > $ time make coccicheck M=drivers/media
> > > real    14m31,975s
> > > user    92m46,656s
> > > sys    0m47,545s
> > …
> > > spatch version 1.1.1-00611-g4388e1d92 compiled with OCaml version 4.13.1
> > …
> > > $ time make coccicheck M=drivers/media
> > > real    33m0,638s
> > > user    218m47,039s
> > > sys    1m13,807s
> > …
> >
> > Would you become interested to increase the measurement granularity another bit?
> >
> > See also:
> > Selection of benchmarks
> > 2018-04-24
> > https://github.com/coccinelle/coccinelle/issues/133
> >
> > Regards,
> > Markus
>
>
>
> --
> Ricardo Ribalda
>
minmax.cocci (text/plain, 3.6 KB)
// SPDX-License-Identifier: GPL-2.0-only
///
/// Check for opencoded min(), max() implementations.
/// Generated patches sometimes require adding a cast to fix compile warning.
/// Warnings/patches scope intentionally limited to a function body.
///
// Confidence: Medium
// Copyright: (C) 2021 Denis Efremov ISPRAS
// Options: --no-includes --include-headers
//
// Keywords: min, max
//

#spatch --disable-iso not_int2

virtual report
virtual org
virtual context
virtual patch

@initialize:python@
@@

def check (p):
  return p[0].current_element != "something_else"

@rmax depends on !patch@
expression x, y;
binary operator cmp = {>, >=};
position p : script:python() { check(p) };
@@

*	((x) cmp@p (y) ? (x) : (y))

@rmaxif depends on !patch@
identifier func;
expression x, y;
expression max_val;
binary operator cmp = {>, >=};
position p : script:python() { check(p) };
@@

*	if ((x) cmp@p (y)) {
*		max_val = (x);
*	} else {
*		max_val = (y);
*	}

// Ignore errcode returns.
@errcode@
position p : script:python() { check(p) };
identifier func;
expression x;
binary operator cmp = {<, <=};
@@

	return ((x) cmp@p 0 ? (x) : 0);

@rmin depends on !patch@
identifier func;
expression x, y;
binary operator cmp = {<, <=};
position p != errcode.p;
position p1 : script:python() { check(p1) };
@@

*	((x) cmp@p1@p (y) ? (x) : (y))

@rminif depends on !patch@
identifier func;
expression x, y;
expression min_val;
binary operator cmp = {<, <=};
position p : script:python() { check(p) };
@@

*	if ((x) cmp@p (y)) {
*		min_val = (x);
*	} else {
*		min_val = (y);
*	}

@pmax depends on patch@
identifier func;
expression x, y;
binary operator cmp = {>=, >};
position p : script:python() { check(p) };
@@

-	((x) cmp@p (y) ? (x) : (y))
+	max(x, y)

@pmaxif depends on patch@
identifier func;
expression x, y;
expression max_val;
binary operator cmp = {>=, >};
position p : script:python() { check(p) };
@@

-	if ((x) cmp@p (y)) {
-		max_val = x;
-	} else {
-		max_val = y;
-	}
+	max_val = max(x, y);

@pmin depends on patch@
identifier func;
expression x, y;
binary operator cmp = {<=, <};
position p != errcode.p;
position p1 : script:python() { check(p1) };
@@

-	((x) cmp@p1@p (y) ? (x) : (y))
+	min(x, y)

@pminif depends on patch@
identifier func;
expression x, y;
expression min_val;
binary operator cmp = {<=, <};
position p : script:python() { check(p) };
@@

-	if ((x) cmp@p (y)) {
-		min_val = x;
-	} else {
-		min_val = y;
-	}
+	min_val = min(x, y);

@script:python depends on report@
p << rmax.p;
@@

for p0 in p:
	coccilib.report.print_report(p0, "WARNING opportunity for max()")

@script:python depends on org@
p << rmax.p;
@@

for p0 in p:
	coccilib.org.print_todo(p0, "WARNING opportunity for max()")

@script:python depends on report@
p << rmaxif.p;
@@

for p0 in p:
	coccilib.report.print_report(p0, "WARNING opportunity for max()")

@script:python depends on org@
p << rmaxif.p;
@@

for p0 in p:
	coccilib.org.print_todo(p0, "WARNING opportunity for max()")

@script:python depends on report@
p << rmin.p;
@@

for p0 in p:
	coccilib.report.print_report(p0, "WARNING opportunity for min()")

@script:python depends on org@
p << rmin.p;
@@

for p0 in p:
	coccilib.org.print_todo(p0, "WARNING opportunity for min()")

@script:python depends on report@
p << rminif.p;
@@

for p0 in p:
	coccilib.report.print_report(p0, "WARNING opportunity for min()")

@script:python depends on org@
p << rminif.p;
@@

for p0 in p:
	coccilib.org.print_todo(p0, "WARNING opportunity for min()")
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.