night-config icon indicating copy to clipboard operation
night-config copied to clipboard

Auto-save batching.

Open LexManos opened this issue 5 years ago • 1 comments

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.

LexManos avatar Jul 02 '19 18:07 LexManos

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.

TheElectronWill avatar Jul 02 '19 21:07 TheElectronWill

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

TheElectronWill avatar Jan 27 '24 16:01 TheElectronWill