sindresorhus / conf

Simple config handling for your app or module
MIT License
1.24k stars 126 forks source link

New Feature - Read data from the RAM (don't always read the file content) #37

Open samuelcarreira opened 6 years ago

samuelcarreira commented 6 years ago

I dug up a little inside the conf module code and appears to me that each get/read function call uses the fs readFileSync to get the data from the config file. If I need to constantly check for a value from the app settings it can lead to performance issues. So my approach is to copy the settings to a global variable 👎 and only use this module to write the config file when some changes occur.

Are any alternative approach to this problem or do you plan to add a feature to kinda "cache the values" and only reads the file when there are some changes?

Thank you

cawa-93 commented 5 years ago

Totally agree. I was very surprised when I looked at the code and saw that all work with the file system is synchronous.

I think it would be much better to make a copy of the data in a global variable. And when you change this data, it is invisible, asynchronously, to synchronize it with a local file, if needed.

sayem314 commented 5 years ago

Yeah, you are right, @sindresorhus any word?

samuelcarreira commented 5 years ago

I am currently working on a alternative library to save the settings. Main highlights:

I will post here when I publish the process

sayem314 commented 5 years ago

@samuelcarreira waiting for this

samuelcarreira commented 4 years ago

@sayem314 I am happy to announce that you can try the beta version of my module https://github.com/samuelcarreira/electron-json-settings-store I need all the feedback that you can provide

sayem314 commented 4 years ago

@sayem314 I am happy to announce that you can try the beta version of my module https://github.com/samuelcarreira/electron-json-settings-store I need all the feedback that you can provide

Is it for electron only? I don't use electron.

papb commented 4 years ago

Also Sindre Sorhus himself recommends his other module electron-store for electron

samuelcarreira commented 4 years ago

@sayem314 It's only for electron

@papb the electron-store is basically a wrapper of the conf module, so the complaints are the same

wkoncki commented 4 years ago

I just want to make everyone aware that this exists and does more or less what is required https://github.com/SamVerschueren/cache-conf It is however seriously outdated, so giving it a refresh may be a better course of work, rather than starting from scratch.

I am also wondering if this is an issue altogether, since modern operating systems usually have their own RAM cache for frequently used files. This is transparent for tools like node, but my guess is that file accessed multiple times a second will be cached, unless you are running very low on RAM.