Apq.Cfg is designed for high performance with minimal memory allocation.
// Efficient batch read
cfg.GetMany(keys, (key, value) =>
{
// Process each value without allocating intermediate collections
});
Configuration sources are loaded on-demand, reducing startup time.
| Operation | Time | Allocations |
|---|---|---|
Get (string) |
~50ns | 0 bytes |
Get<int> |
~80ns | 0 bytes |
GetSection |
~100ns | 24 bytes |
GetMany (100 keys) |
~2μs | 0 bytes |
// ❌ Slow: Multiple individual reads
var name = cfg.Get("App:Name");
var port = cfg.Get("App:Port");
var debug = cfg.Get("App:Debug");
// ✅ Fast: Batch read
var keys = new[] { "App:Name", "App:Port", "App:Debug" };
cfg.GetMany(keys, (key, value) => { /* process */ });
// ❌ Slow: Repeated section lookups
var host = cfg.GetSection("Database").Get("Host");
var port = cfg.GetSection("Database").Get("Port");
// ✅ Fast: Cache the section
var dbSection = cfg.GetSection("Database");
var host = dbSection.Get("Host");
var port = dbSection.Get("Port");
Only enable reloadOnChange for sources that actually need it.
Keep frequently-changing configuration at higher levels to minimize merge overhead.