Performance

Speed up rebuilds with the incremental data step and speed up exports with parallel rendering and workstation GC.

On this page
bash
DOTNET_gcServer=0 dotnet run -c Release -- --bevel-build

Two things can be slow: the data step during dotnet build, and the export. Bevel makes both fast by default. This page shows you what to change when you need more.

Fast rebuilds and dotnet watch

The data step skips itself when nothing changed, so a second dotnet build is quick. It runs again when any of these change:

  • A file under Data/, such as .cs, .md or .json.
  • A file a data source read, including files outside Data/, and a file added to or removed from a wildcard folder.
  • appsettings*.json or bevel.json.
  • The resolved build environment.
  • The project file or the prebuild tool.

dotnet build --no-incremental and a rebuild also run it. dotnet watch rebuilds when you edit content under Data/, not only code.

Files Bevel cannot see

Bevel does not see databases or APIs. A loader that reads one must run every time:

MySite.csprojxml
<PropertyGroup>
  <BevelPrebuildAlwaysRun>true</BevelPrebuildAlwaysRun>
</PropertyGroup>

A loader that reads a file itself must register it, so editing the file reruns the step.

csharp
context.RegisterInputFile(path);                  // a file
context.RegisterInputDirectory(path);             // a folder listing
context.RegisterRecursiveInputDirectory(path);    // a folder read recursively

Files you read through context.Read*Async, ReadAllText and FileExists register themselves. In a processor, ctx.ReadAllText("@/path") also registers the file.

Faster exports

An export plans and checks every output path, renders pages, compares with the previous manifest, commits, then cleans up and writes the manifest.

Parallel rendering

Pages render at the same time, up to ExportParallelism. The default is Math.Clamp(Environment.ProcessorCount / 2, 1, 8). The files and .bevel-output.json are byte-identical for every value.

Program.cscsharp
builder.AddBevel(options => options.ExportParallelism = 1); // one page at a time

Each page renders in its own scope, but singletons, static fields and caches are shared. Page components and the services they call must be thread-safe. If yours are not, set ExportParallelism = 1. See BevelOptions.ExportParallelism.

If several pages fail, Bevel throws the error of the first failing route in route order, whatever the timing.

Use workstation GC

The Web SDK turns on server GC. It suits a busy site, but an export is short-lived and the garbage piles up to gigabytes. Set DOTNET_gcServer=0 for dotnet run -- --bevel-build and in CI. Or cap the heap with DOTNET_GCHeapHardLimit=0x40000000 for 1 GB.

The publish export (MSBuild.BevelExportOnPublish) already starts its child process with DOTNET_gcServer=0, unless you set it. Your published site's GC does not change.

Measured results

A stress site with 1,000 and 10,000 generated posts, on an Apple M4 Pro with 14 cores, in Release:

1,000 posts 10,000 posts
Before (sequential), server GC 2.5–2.9 s, 765 MB 27.4–27.9 s, 2.6 GB
Before, DOTNET_gcServer=0 2.2–2.8 s, 224 MB 27.4–28.1 s, 1.0–1.1 GB
Now (7 workers), server GC 0.74 s, 643 MB 8.9–9.2 s, 3.4–3.6 GB
Now, DOTNET_gcServer=0 0.84 s, 238 MB 9.3–9.6 s, 1.4 GB

Parallel rendering uses more CPU in total, about 1.7 times the user time at 10,000 posts, and a larger heap. That is why workstation GC matters more now. If memory is tight, lower ExportParallelism.

The data step

The data step also got faster. On the same 10,000-post site, it went from 7.7 s to 4.2 s, and peak memory from 1.9 GB to 1.4 GB. You do not need to change anything.