Skip to content

Small counters update#207

Merged
Bruno02468 merged 1 commit into
MystranSolver:devfrom
Bruno02468:counter_performance
Apr 7, 2026
Merged

Small counters update#207
Bruno02468 merged 1 commit into
MystranSolver:devfrom
Bruno02468:counter_performance

Conversation

@Bruno02468

Copy link
Copy Markdown
Member

I bring two updates to the counters system I developed a while ago.

First, we had an excess of writes. Counters write to the screen when the percentage is 0% or 100% (first and last writes) and whenever the percentage changes. That means that a sub-second counter will write 101lines of output. That's an issue when parsing output or when writing to non-TTY descriptors, such as files or pipes.

To alleviate that, I separated the counter updates into "forced" (the first and last ones) and "non-forced" (all the others, when the percentage merely changes). I then limited "non-forced" updates to one per second. Now, instantaneous counters will produce at most 3 lines of output (as opposed to 101) and longer ones will average one per second.

Second, we had some issues with counters not finishing. CYCLE and EXIT instructions can muddle up the count. One could just directly write the desired total to force a counter to finish up, but that's hacky. Instead, I made it so the input to COUNTER_PROGRESS is checked for sign. If negative, it'll force the new value to be the desired total.

Therefore, a "dodgy" loop can just call COUNTER_PROGRESS(-1) outside the loop, thus ensuring that the counter finishes properly and a crash does not happen when a new one is started.

I suggest developers use this feature only as needed. In all the counters I converted to this new system, I have never had to force a counter to finish. In fact, I have identified actual MYSTRAN bugs after poorly-planned loops failed to finish their associated counter... so I'd first make sure that's not the case before forcing a counter to finish. Even when there are CYCLEs, placing the COUNTER_PROGRESS call at the top does the trick. EXITs are more complicated though, and might justify the usage of such a trick.

Finally, I'd like to thank @victorkemp for identifying these issues and helping me arrive at this solution!

@Bruno02468 Bruno02468 merged commit 54a43bd into MystranSolver:dev Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant