Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mechanism to disable creating new worlds #56639

Merged
merged 1 commit into from
Nov 28, 2024

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Nov 21, 2024

As a performance optimization, when you are certain only to run all remaining code in a fixed world (e.g. not even eval a new closure or comprehension), such as when all code is defined in a system image and not being used interactively, you can put a call to:

Base.Experimental.disable_new_worlds()

Which will enable performance optimizations around avoiding tracking backedges and invalidations.

base/experimental.jl Outdated Show resolved Hide resolved
@topolarity
Copy link
Member

This also means that you can't load any more code either, is that right?

Folks may not think of using Foo as world-incrementing, but of course it is

"""
Base.Experimental.disable_new_worlds()

Mark that no new worlds (methods additions, deletions, etc) are permitted to be
Copy link
Member

Choose a reason for hiding this comment

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

It's probably worth mentioning that this transition is permanent (if I understand correctly)

@vtjnash
Copy link
Member Author

vtjnash commented Nov 21, 2024

This also means that you can't load any more code either, is that right?

You currently can (though Keno might remove that soon), since defining code isn't a world operation, only adding methods, so the methods won't "take effect" but the loading itself will be successful.

@JeffBezanson
Copy link
Member

JeffBezanson commented Nov 22, 2024

That's neat --- I suppose you could load and use a package that just defines some constants or something. But in practice of course that is not really a requirement in these cases AFAIK.

JL_DLLEXPORT void jl_disable_new_worlds(void)
{
if (jl_generating_output())
jl_error("Disabling Method changes is not possible when generating output.");
Copy link
Member

Choose a reason for hiding this comment

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

But that's the only time I want to do it? 😂 How do you use this to generate "sealed" system images?

@topolarity
Copy link
Member

I think it's more confusing than it is neat.

As a user, I would think it's a bug for Julia to claim to have loaded a package but not have applied its methods to the dispatch table

@JeffBezanson
Copy link
Member

JeffBezanson commented Nov 22, 2024

Yeah no argument there; I don't think there is a real use case. (To clarify: I'm only referring to loading a package that defines methods, but ignoring those methods, as having no use case, not this PR generally.)

@Drvi
Copy link
Contributor

Drvi commented Nov 26, 2024

Just to add a bit of context -- we use this feature already to quickly load "cache packages", packages that only contain precompile statements that our users generated by running queries using our product (and that we compile behind the scenes). Since we can't precompile all user queries into our product ahead of time, these cache packages are a sort of a dynamically generated extension of the system image.

@vtjnash
Copy link
Member Author

vtjnash commented Nov 27, 2024

I don't think there is a real use case. (To clarify: I'm only referring to loading a package that defines methods, but ignoring those methods

I've been asked for this specific feature several times by several different people, so it isn't without its uses. Indeed, we even already have a number of essential packages in the ecosystem whose only purpose in existing is to be able to define types without providing any new method definitions, so we've been moving towards making that possible to do for any package, though this is not relevant to this PR.

@vtjnash vtjnash force-pushed the jn/disable-new-worlds branch from aaaba65 to 7f39d37 Compare November 27, 2024 19:51
@vtjnash vtjnash added the merge me PR is reviewed. Merge when all tests are passing label Nov 27, 2024
As a performance optimization, when you are certain only to run all
remaining code in a fixed world (e.g. not even eval a new closure or
comprehension), such as when all code is defined in a system image and
not being used interactively, you can put a call to:

    Base.Experimental.disable_new_worlds()

Which will enable performance optimizations around avoiding tracking
backedges and invalidations.
@vtjnash vtjnash force-pushed the jn/disable-new-worlds branch from 7f39d37 to ef0882e Compare November 27, 2024 23:01
@IanButterworth IanButterworth merged commit 7e2e0ae into master Nov 28, 2024
7 checks passed
@IanButterworth IanButterworth deleted the jn/disable-new-worlds branch November 28, 2024 03:15
@giordano giordano removed the merge me PR is reviewed. Merge when all tests are passing label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:latency Compiler latency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants