-
Notifications
You must be signed in to change notification settings - Fork 0
Defaults Trimming
As users customize your addon, the SavedVariables file gradually grows to include every setting that has been modified. Over time, many of these stored values may become identical to their default values, resulting in unnecessary data being written to disk.
LibSavedVars can automatically remove these redundant values through defaults trimming.
Defaults trimming compares the saved variables against the defaults table and removes any values that exactly match their defaults. Because those values are already supplied by the defaults table when the addon loads, storing them is unnecessary.
Consider the following defaults:
local defaults = {
enabled = true,
opacity = 0.8,
window = {
x = 100,
y = 100,
},
}Suppose the player's SavedVariables contain:
{
enabled = true,
opacity = 0.6,
window = {
x = 100,
y = 250,
},
}After trimming, the saved data becomes:
{
opacity = 0.6,
window = {
y = 250,
},
}The values enabled and window.x are removed because they match their defaults. When the addon loads, LibSavedVars automatically supplies those values from the defaults table, so the behavior remains exactly the same.
Defaults trimming is optional and must be enabled for each saved variables object.
local settings = LibSavedVars:NewAccountWide(
"MyAddonSavedVariables",
1,
nil,
defaults
)
settings:EnableDefaultsTrimming()Once enabled, LibSavedVars automatically trims matching values before the SavedVariables are written during logout or /reloadui.
No additional code is required.
When ESO saves your addon's data, LibSavedVars:
- Compares the saved variables against the defaults table.
- Removes values that are identical to their defaults.
- Removes tables that become empty after trimming.
- Leaves all modified values intact.
The process is completely transparent to your addon.
Defaults trimming works recursively through nested tables.
For example:
Defaults:
local defaults = {
ui = {
minimap = {
visible = true,
size = 250,
},
},
}Saved variables before trimming:
{
ui = {
minimap = {
visible = true,
size = 300,
},
},
}After trimming:
{
ui = {
minimap = {
size = 300,
},
},
}Only the value that differs from the default remains.
Defaults trimming provides several advantages:
- Smaller SavedVariables files.
- Reduced disk usage.
- Cleaner saved data that contains only user-customized values.
- Easier inspection and debugging of SavedVariables.
- Automatic cleanup with no changes required in your addon logic.
Because default values are restored automatically when the addon loads, trimming does not change how your addon behaves.
Defaults trimming works best when:
- Your defaults table accurately represents the intended initial configuration.
- Default values are treated as read-only after the saved variables are created.
- Your addon accesses settings through LibSavedVars rather than assuming every value is physically stored.
Defaults trimming is especially beneficial for large addons with many configuration options, where storing every default value would significantly increase the size of the SavedVariables file.
Defaults trimming keeps your SavedVariables as small and clean as possible by removing values that are already provided by the defaults table. The player's experience is unchanged—the same settings are available after loading—but only the values that differ from the defaults are written to disk.
For most addons, enabling defaults trimming is a simple way to reduce file size and maintain cleaner saved data with no additional maintenance.