Skip to content

Set max_methods 1 for several IO functions#60391

Open
jakobnissen wants to merge 2 commits intoJuliaLang:masterfrom
jakobnissen:io_methods
Open

Set max_methods 1 for several IO functions#60391
jakobnissen wants to merge 2 commits intoJuliaLang:masterfrom
jakobnissen:io_methods

Conversation

@jakobnissen
Copy link
Copy Markdown
Member

This reduces the number of invalidations of loading BufferIO.jl commit 957f141 from 1026 to 549. The large number of invalidations come from excessive world splitting on un-inferred IO objects, which, ironically, are probably intentionally left un-inferred to reduce unnecessary compilation.

This is a poor bandaid solution: World splitting delenda est and all that. If that is not feasible, then an option to selectively disable it e.g. through a future @max_methods 0 would impove the situation. For example, about 400 methods are invalidated due to the addition of a new write(::T, ::Char) method, which invalidates the single, world split write(::IO, ::Char) method.

However, deeper fixes of this issue is outside the scope of this PR.

This reduces the number of invalidations of loading BufferIO.jl commit 957f141
from 1026 to 549. The large number of invalidations come from excessive world
splitting on un-inferred IO objects, which, ironically, are probably
intentionally left un-inferred to reduce unnecessary compilation.

This is a poor bandaid solution: World splitting delenda est and all that.
If that is not feasible, then an option to selectively disable it e.g. through
a future `@max_methods 0` would impove the situation. For example, about 400
methods are invalidated due to the addition of a new `write(::T, ::Char)`
method, which invalidates the single, world split `write(::IO, ::Char)` method.

However, deeper fixes of this issue is outside the scope of this PR.
@jakobnissen jakobnissen added io Involving the I/O subsystem: libuv, read, write, etc. invalidations labels Dec 16, 2025
@JamesWrigley
Copy link
Copy Markdown
Member

While you're at it, could we also do the same for lock and unlock? That removes the vast majority of invalidations in IJulia, from 3095 to 221.

@jakobnissen
Copy link
Copy Markdown
Member Author

That will broaden the scope of this PR beyond IO functions, since lock is also used for non-IO types, such as AbstractLocks. Max methods can only be set on a per-function level.

@JamesWrigley
Copy link
Copy Markdown
Member

isopen and close are also used for non-IO types though? But it's not a big deal, I can open another PR.

@jakobnissen
Copy link
Copy Markdown
Member Author

Yes, channels and timers also have a notion of opening / closing

@KristofferC
Copy link
Copy Markdown
Member

I pushed a small tweak that should make the failing test go through.

@jakobnissen
Copy link
Copy Markdown
Member Author

Errors look to be network errors, AFAICT

@nsajko
Copy link
Copy Markdown
Member

nsajko commented Jan 24, 2026

xref PR #59377

Read binary data from an I/O stream or file, filling in `array`.
"""
function read! end
typeof(read!).name.max_methods = UInt8(1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if a method of read! gets defined and a method instance gets compiled/inferred before you change max_methods here? Would it cause miscompilation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalidations io Involving the I/O subsystem: libuv, read, write, etc. status: waiting for PR reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants