chiapos icon indicating copy to clipboard operation
chiapos copied to clipboard

Remove global variable

Open nazar-pc opened this issue 2 years ago • 7 comments

Generally bad practice to use global variables and easily fixable in this case

nazar-pc avatar Mar 06 '23 17:03 nazar-pc

I suspect that this will make the code run slower, because of the extra indirections. Is there a stronger argument than "generally bad practice"?

arvidn avatar Mar 18 '23 08:03 arvidn

I don't think you'll be able to detect any difference in performance here. CPUs are crazy good at these kinds of patterns.

My context is that I was working on turning this CLI into a library and needed to call it potentially many times from the same process, so having global variables was undesirable. There is one more place with static variable in disk reads that would still be a blocker for that though.

I saw the opportunity to improve code a bit and decided to contribute back, but if it is not a welcome change that is fine too.

nazar-pc avatar Mar 18 '23 12:03 nazar-pc

we have measured performance degradation with smaller changes in the past. If you can demonstrate that there's no slow-down, I think this is a fine change. I think your use case is a pretty strong argument and might be worth a small slow-down. But I think it would have to be quantified (and not assumed or guessed)

arvidn avatar Mar 18 '23 12:03 arvidn

on the other hand, given bladebit, perhaps we don't care so much about a performance degradation in chiapos.

arvidn avatar Mar 18 '23 12:03 arvidn

I ran ProofOfSpace with tmpfs a few times on 13900k and took the best result out of a few runs.

Before:

k22 7.786
k25 65.272

After:

k22 7.752
k25 63.996

I'm not sure it became faster, but shouldn't be significantly slower either. My test was not super scientific, I have a bunch of things running in background on my machine.

nazar-pc avatar Mar 18 '23 12:03 nazar-pc

We're short on time to review this, but if you fork chiapos and it works well for you, we'll consider up-streaming it.

MumfMeisterT avatar Mar 23 '23 19:03 MumfMeisterT

'This PR has been flagged as stale due to no activity for over 60 days. It will not be automatically closed, but it has been given a stale-pr label and should be manually reviewed.'

github-actions[bot] avatar May 23 '23 11:05 github-actions[bot]