night-config
night-config copied to clipboard
Auto-save batching.
I noticed this while debugging an unrelated issue in Forge. But there does not seem to be a way to batch auto-save operations. This is especially noticeable in synced configs. As well as commented configs. Where creating a complex config file for the first time could easily cause the file to be written several hundred times. Notably during the correct operation, as any correction would cause a write.
I'm requesting a feature to allow us to batch these writes to save both CPU cycles and disc IO.
Request heard! Async configs do provide some light batching-ish (it's actually a side-effect that wasn't designed for batching and I agree that it isn't enough), sync configs do not. I'll include that in the next release, probably with a manual way to declare a batch and an automatic time- or count-based batching.
In the next version you will be able to batch your operations with bulkUpdate
and bulkCommentedUpdate
. Auto-saving will only occur after all your operations. See #152.
Example:
FileConfig config = FileConfig.builder().autosave().build(); // get your FileConfig as usual
config.bulkUpdate(conf -> {
// multiple operations on conf
});
// save() is automatically called *after* all your operations