← 输入框|github.com|刷新
Skip to content

Run callable recipe generators in process - #153

Open
akritkbehera wants to merge 1 commit into
bitsorg:mainfrom
akritkbehera:optimize-generated-recipes
Open

akritkbehera wants to merge 1 commit into
bitsorg:mainfrom
akritkbehera:optimize-generated-recipes

Conversation

@akritkbehera

@akritkbehera akritkbehera commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Allow generated recipes to provide a Python generate callable. Bits runs the callable in the current process and passes its text output through the existing recipe parser. This avoids starting a Python subprocess for each recipe that opts in.

Generators that provide only command continue to work as before. If a callable raises and a fallback command is available, bits runs the command to preserve its diagnostics and exit behavior.

Performance

Performance

A CMSSW dependency resolution profile spent 22.35 seconds out of approximately 25 seconds in generated recipe subprocesses, about 89% of that phase.

With the companion recipe changes that opt into callables, one local bits build cmssw-tools --dry-run comparison measured:

Configuration Wall time
Command based generators 97.597 s
Callable generators 23.492 s

That run was 4.15× as fast, a 76% reduction in wall time. These are local measurements.

@pbuncic

pbuncic commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Nice — the opt-in is clean and it's inert for everyone who doesn't use it. Can you port this to optimisation branch which I am about to merge with main>

Three issues:

  1. Make the fallback visible.
python
except Exception:
  if self.command is None:
    raise
  # Reuse the legacy command's diagnostic and exit status on failure.

The exception is discarded — not logged, not chained. The whole case for this change is 97.6 s → 23.5 s, and as written a callable that breaks on one platform or one package silently reverts to the subprocess path. The build still succeeds, so nobody finds out until somebody re-profiles; the speedup you measured can quietly disappear. It also means that if the fallback command then fails, getoutput → dieOnError reports the command's error and the callable's actual bug is gone.

Two lines keep it:

python
except Exception as exc:
  if self.command is None:
    raise
  warning("generated recipe %s: callable failed (%s); falling back to command", self.url, exc)

and raise ... from exc if you'd rather re-raise with the chain intact. Worth noting too that an in-process callable which fails after side effects leaves them in place, and the command then runs on top — a subprocess couldn't do that.

  1. A couple of tests. tests/test_parseRecipe.py is the natural home, and four cases cover the behaviour: callable only; callable raises with a command present (falls back); callable raises with no command (re-raises); command-only unchanged. The last one is the one that protects everybody else.

  2. CHANGELOG and docs/REFERENCE.md. generate is now public API for recipe authors, and the docs are where one consequence belongs: a generator that adopts generate rehashes its packages once. The recipe text is a hashed input (hashing.py:165-170, via normalize_recipe_for_hash, which forgives full-line comments and blank lines but nothing else), so any difference between the callable's text and the command's text changes those packages' hashes. For CMS that's a rebuild, and nothing else is affected because the opt-in is per generator — but the next community to adopt it may be on the store, and this should be written down rather than rediscovered.

Minor, non-blocking:

self.generate().strip() assumes a string; a callable returning None raises AttributeError, which the except then turns into a silent fallback. An explicit check naming the package would fail more usefully.

A generator dict with neither generate nor command dies with a bare KeyError: 'command'. Naming the package would help whoever wrote it.

obj["command"] if self.generate is None else obj.get("command") reads awkwardly for what it does.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants