Refactor import caching to per-interpreter model#48
Open
Conversation
94728a1 to
379c81c
Compare
- Replace per-process import caching with global ETS registry - Imports are applied to sys.modules when interpreters are created - Remove deprecated loop import NIFs (loop_import_module, etc.) - Add interp_apply_imports/2 and interp_flush_imports/2 NIFs - flush_imports now removes modules from sys.modules in all interpreters - Contexts and loops sharing the same interpreter share sys.modules - Add py:init_import_registry/0 called on application startup - Add py:get_imports/0, py:del_import/1,2, py:clear_imports/0 - Add py_context:flush_imports/2 and py_context_router:flush_all_imports/1 - Add del_import_reimport_test verifying module removal from sys.modules
379c81c to
bc357f5
Compare
Replace del_import with generation-based pool slot recycling. When flush_imports is called, all pool slots are marked stale. When a stale slot's usage count drops to 0, the subinterpreter is destroyed and reinitialized with a fresh one. Changes: - Add usage_count, marked_stale, generation to subinterp_slot_t - Add subinterp_pool_acquire/release/flush_generation functions - Remove del_import/1,2 from py.erl (no longer needed) - Update flush_imports to use generation-based approach - Remove del_import tests from test suite
flush_imports now works correctly for all context types: - Subinterpreter pool: slots marked stale and replaced - OWN_GIL: each has own subinterpreter destroyed with context - Main interpreter: cache generation checked on module access Added unconditional import_cache_get_generation() and import_cache_flush_generation() functions that work regardless of subinterpreter support.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sys.moduleswhen interpreters are createdloop_import_module, etc.)interp_apply_imports/2andinterp_flush_imports/1NIFssys.modulesAPI Changes
New functions:
py:init_import_registry/0- called on application startuppy:get_imports/0- list all registered importspy:del_import/1,2- remove imports from registrypy:clear_imports/0- clear all registered importspy_context:flush_imports/1- flush imports from a contextpy_context_router:flush_all_imports/0- flush imports from all contextsRemoved exports:
py_event_loop_pool:import/1,2py_event_loop_pool:flush_imports/0py_event_loop_pool:import_stats/0py_event_loop_pool:import_list/0