← Back to Usage Guide Index
M7BootStrap is designed for fast runtime package loading, but there are strategies and caveats to keep in mind when optimizing performance.
By default, M7BootStrap loads packages in parallel for maximum throughput. This can drastically reduce load times when fetching from high-latency sources.
Caveat: Parallel loading does not guarantee dependency order. If strict load order is required, handle integration in a post-load hook.
Example:
const onLoad = [
"#runner.mount",
(sys, ctx) => integrateDependencies(sys,ctx)
];
await bootstrap.load(resources, {load:onLoad});By default, bootstrap keeps a internal limiter of 8 simultaneous processes per component (repo,module,assets, packages). However a large package list will be queued up at once , as will a large list of assets,etc.
If you are loading many large packages at once, unbounded parallelism may cause:
- Network congestion
- Memory spikes
- API rate limiting (for authenticated sources)
Consider breaking up very large packages into smaller components, and use a concurrency limiter for controlled parallelism:
import { createLimiter } from ".<path_to_bootstrap>/utils/limiter.js";
const limit = createLimiter(8); // max 8 concurrent requests
await Promise.all(resources.map(r => limit(() => bootstrap.load([r]))));Or use built in parallelism (assuming the package size itself is not too large):
bootstrap.load(resources, {limit:8,load,error});Leverage caching at multiple levels:
- m7Fetch built-in cache (via net.batch)
- HTTP caching via
Cache-Controlheaders - In-memory registries (e.g., keeping package definitions around after first load)
Example: Check .packages registry before reloading:
if (!bootstrap.packages.isLoaded("scene:chess")) {
await bootstrap.load(["scene:chess"]);
}For production, consider bundling multiple related assets into a single package to reduce:
- HTTP request overhead
- Round-trip latency
Avoid loading every package at startup — defer loading until it’s actually needed in runtime:
async function loadWhenNeeded(pkg) {
if (!bootstrap.packages.isLoaded(pkg)) {
await bootstrap.load([pkg]);
}
}While inline packages avoid network requests, embedding large binary assets directly in JSON will:
- Increase initial script size
- Delay JS parse/compile times
Prefer URLs for large assets instead of embedding them.
Related Topics: