Skip to content

Move the gc disabling to looptime's chronometers - #1335

Merged
nolar merged 1 commit into
mainfrom
gc-disable-in-looptime
Oct 12, 2026
Merged

nolar merged 1 commit into
mainfrom
gc-disable-in-looptime

Conversation

@nolar

@nolar nolar commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

A rework of an issue fixed in c1e1462, but the fix is now a part of the default behaviour of looptime's chronometers.

For clarity: it is not proven that the issue was caused by garbage collection, it is just the most viable explanation. It is also not proven that disabling the gc actually fixed the issue. As experiments show, the mere import gc on the module level already fixes the bug — probably by shifting the gc point earlier/later but outside of the chronometer. Even a switch to looptime's wip branch in this PR, which also fixes the issue, might actually fix it because import gc happens deep there and changes the balance. However, let this "fix" be — as it at least seems viable, despite unproven.

@nolar nolar added the bug Something isn't working label Oct 5, 2026
Comment thread pyproject.toml Outdated
@nolar
nolar force-pushed the gc-disable-in-looptime branch from 56fb937 to 1b0f34e Compare October 5, 2026 12:16
nolar referenced this pull request Oct 5, 2026
Due to new three tests, another completely unrelated test (`test_threadsafe_indeed_works()`) started to fail unusually: only in Python 3.12 full-auth; works fine in other 3.12 modes and other full-auth versions — but 100% reproducible in CI and in CI only (not locally).

Experiments have shown that the issue happens only when all three tests are active (1+2+3), while the test run passes with only one or two tests (1+2, 2+3, 1+3). Time measurements indicated that the extra time (≈0.13s) was spent on operations so routine that they were not even suspected: exiting a function or adding an item to a list, not in the actual thread starting or something resource-intense. Besides, simple time measurements themselves caused the tests to pass sometimes.

The only suspicion was that something was happening under the hood at these moments, and the garbage collection was the number one candidate (in the absence of any parallel/concurrent activities). Probably, the amount of garbage accumulated from all tests was anyway huge, and adding three more tests pushed it beyond the threshold, which accidentally caused the garbage collection in these particular real-clock tests (previously, probably happened in other tests that did not notice anything). Just a sequence of accidents.

Either way, enforcing the garbage collection before the test and disabling the garbage collection during the real-clock tests fixed the issue. Pure luck.

Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
A rework of an issue fixed in c1e1462, but the fix is now a part of the default behaviour of looptime's chronometers.

Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
@nolar
nolar force-pushed the gc-disable-in-looptime branch from 1b0f34e to 74cf7ea Compare October 12, 2026 12:50
@nolar
nolar marked this pull request as ready for review October 12, 2026 12:51
@nolar
nolar merged commit bdfc316 into main Oct 12, 2026
36 checks passed
@nolar
nolar deleted the gc-disable-in-looptime branch October 12, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant