agentleFS
malloydatamalloydata/publisher/skills/malloy-materialization-tuning/SKILL.md

malloy-materialization-tuning

Skill116 starsChanged 2 months agoMITView on GitHub

Optimize a package's Malloy Persistence materializations for cost and performance using the malloy-pub CLI and the materialization history. Recommend what to persist, what to stop persisting, and how to schedule/scope it. Use when the user asks to make a package cheaper or faster, tune persistence, decide what to materialize, or review persist/schedule choices.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Look across several runs, not one: the pattern over the recent history (how often it rebuilds, how much it reuses, how long it takes) is …

    line 57
  2. Very specific:

    Add a persist source: add the #@ persist annotation in the .malloy file (use the modeling workflow to validate and reload), then rebuild so …

    line 72
  3. Very specific:

    Remove a persist source: delete the #@ persist annotation, then drop the old run's tables before rebuilding what remains:

    line 78
  4. Distinctive:

    After applying, re-run Step 2 on the next few builds to confirm the change did what you predicted (more reuse, shorter builds, or a table …

    line 98

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md
<!-- Copyright (c) Credible Data Inc. SPDX-License-Identifier: MIT -->

Tuning materializations for cost and performance

This skill turns the signals the open-source Publisher already records (the materialization history, per-run timings, and which sources were built vs reused) into concrete, recommendations-only advice: which sources to persist, which to stop persisting, and how to schedule and scope them. It is the local counterpart to the platform's usage-driven optimization: the Publisher has the raw signals, and you read them with the malloy-pub CLI.

Recommendations only. Never change a model, schedule, or scope without the user's explicit go-ahead. Present the findings and the proposed edits, then apply them only when asked. Persisting the wrong source wastes storage and rebuild time; unpersisting a hot one makes queries slow. Let the user decide.

Assumes the malloy-pub CLI is on PATH and points at the server (--url or MALLOY_PUBLISHER_URL, default http://localhost:4000). Substitute the real environment and package for <env> / <pkg>.

Step 1: Take inventory

Establish what the package persists today and how it is governed.

  • Persist sources: the sources annotated #@ persist name="…" in the package's .malloy files. Read the models (or get_context the package) to list them.
  • Schedule + scope:

    malloy-pub schedule view --environment <env> --package <pkg>

    This prints the cron (or none, meaning publish / on-demand only), the persist scope (package = artifacts reused across versions; version = per published version), and whether a freshness policy is set. A control-plane-managed package (manifestLocation set) is refreshed by the control plane, not the standalone scheduler, so leave its cadence alone.

Step 2: Read the materialization history

The history is where cost lives. Each run records its trigger, timing, and how many sources were built vs reused.

  • For one package (newest first). A materialization is a run of one package's persist sources, so this is the listing; to review a whole environment, read each package in turn (malloy-pub list package --environment <env> names them):

    malloy-pub list materialization --environment <env> --package <pkg>

    Columns: ID, Status, Trigger (SCHEDULER vs ON_DEMAND), Started, Completed, Error.

  • A single run's detail (the cost signals):

    malloy-pub get materialization <id> --environment <env> --package <pkg>

    In the JSON, read:

    • metadata.durationMs: how long the build took.
    • metadata.sourcesBuilt vs metadata.sourcesReused: how much work each run actually did. A run that is nearly all reused is cheap; one that is nearly all built every time is where cost accumulates.
    • metadata.sourcesRefused and metadata.refusedSources: sources the eligibility gate skipped. Each one serves live on every query, so a refused source the user expected to be persisted is a finding in its own right; its entry's message says what to change.
    • metadata.trigger: SCHEDULER (a cron fired it) or ON_DEMAND.
    • manifest.entries[*]: the persisted sources: sourceName, physicalTableName, realization.

Look across several runs, not one: the pattern over the recent history (how often it rebuilds, how much it reuses, how long it takes) is the signal.

Step 3: Analyze and recommend

Weigh rebuild cost against query benefit. Common findings:

  • Persist candidate: an expensive, frequently-queried source that is not persisted (recomputed on every query). Recommend adding #@ persist name="…". Strongest when the source is a heavy aggregate/join reused by many queries and its inputs change slowly. If the source carries a #(access_filter) gate, check which case it is first. A gate reached only through a join_*, or inherited from a base it cannot be attributed to, means the colocated persist is refused - the build skips it and it serves live - so do not recommend persisting it at all. Where the gate is provably the source's own row filter the persist is admitted, and then only recommend it alongside a freshness window (freshness.fallback="live"): the gating column freezes at build time, so without one a revoked row can be served under its old access decision indefinitely (see skill:malloy-materialization, which also covers where that window does and does not bind).
  • Removal candidate: a persisted source that is cheap to compute, rarely queried, or rebuilt far more often than it is read. Recommend dropping the #@ persist annotation (and its table): the storage + rebuild cost is not buying anything.
  • Cadence mismatch: a SCHEDULER cadence out of step with how fast the data changes or how long a build takes. If most scheduled runs are all-reused (nothing changed), the cron is too frequent, so loosen it. If queries routinely read stale data, tighten it. If the build's durationMs approaches the interval, the cadence is too aggressive.
  • Scope mismatch: scope: version re-materializes per published version (right when versions must be isolated, e.g. a schedule); scope: package reuses one lineage across versions (cheaper when versions can share). A schedule requires version. If a package carries a schedule it does not need, clearing the schedule frees it to use the cheaper package scope.

Frame each recommendation with the evidence from Step 2 (the run IDs, timings, built/reused counts) so the user can judge it.

Step 4: Apply (only once approved)

  • Add a persist source: add the #@ persist annotation in the .malloy file (use the modeling workflow to validate and reload), then rebuild so it is materialized:

    malloy-pub materialize --environment <env> --package <pkg> --wait
  • Remove a persist source: delete the #@ persist annotation, then drop the old run's tables before rebuilding what remains:

    malloy-pub delete materialization <id> --environment <env> --package <pkg> --drop-tables
    malloy-pub materialize --environment <env> --package <pkg> --wait

    --drop-tables drops every physical table in that run's manifest, not just the removed source's: auto-run assigns stable table names and carries unchanged sources forward, so an old run's manifest names tables a newer manifest still serves. Do the drop first, then rebuild: materialize --wait re-creates every source that is still persisted, ending in the desired state. Dropping a run whose tables the current serving manifest depends on, without an immediate rebuild, breaks queries (Table ... does not exist).

  • Change the schedule / cadence:

    malloy-pub schedule set "0 6 * * *" --environment <env> --package <pkg>   # 5-field UTC cron
    malloy-pub schedule clear --environment <env> --package <pkg>

    set also sets scope: version (a schedule requires it); the server rejects an invalid cron or an illegal scope/freshness combination, so a rejection means the change was unsafe.

  • Change the scope: scope is declared in the package's publisher.json under materialization ("scope": "package" or "version"; the root-level form is deprecated but still read). Edit it there, then reload/republish the package. Remember a schedule pins scope to version, so clear the schedule first if moving to package.

After applying, re-run Step 2 on the next few builds to confirm the change did what you predicted (more reuse, shorter builds, or a table that is actually read).

What this skill does not do

  • It does not decide for the user or apply changes silently; every edit needs an explicit go-ahead.
  • It cannot see per-query read counts (the open-source Publisher records build history, not query-level table usage), so "rarely queried" is a judgment from the model and the user's knowledge, not a measured metric. Say so when it matters.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.