workhorsy / py-cpuinfo

A module for getting CPU info with pure Python
MIT License
312 stars 59 forks source link

cache result? #206

Open maxnoe opened 11 months ago

maxnoe commented 11 months ago

get_cpu_info takes a relatively long time and seems to do the full work everytime the function is called.

However, there is probably no way this information can change during the lifetime of a running program (maybe I am missing something?).

So the result could be cached and returned immediately on subsequent calls

anttimc commented 11 months ago

I found that there is a one-second waiting time when the process just sleeps. See this issue/comment: https://github.com/workhorsy/py-cpuinfo/issues/205#issuecomment-1833653828

Therefore, I would try to do something else than caching. The one second overhead is there even if the result is cached, and it accumulates per process you run. If you consider a very quick process that calls as a dependency get_cpu_info, and this process is called hundrends or thousands of times per hour, then this overhead becomes unacceptable.

maxnoe commented 11 months ago

oh wow... I didn't realize that this 1 second might not really be needed when patching pytables yesterday to not run this on import but just when needed.

It would really be great to have fine-grained control about what information is gathered, since tables only needs cache sizes I think.