mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	gh-91048: Refactor and optimize remote debugging module (#134652)
Completely refactor Modules/_remote_debugging_module.c with improved
code organization, replacing scattered reference counting and error
handling with centralized goto error paths. This cleanup improves
maintainability and reduces code duplication throughout the module while
preserving the same external API.
Implement memory page caching optimization in Python/remote_debug.h to
avoid repeated reads of the same memory regions during debugging
operations. The cache stores previously read memory pages and reuses
them for subsequent reads, significantly reducing system calls and
improving performance.
Add code object caching mechanism with a new code_object_generation
field in the interpreter state that tracks when code object caches need
invalidation. This allows efficient reuse of parsed code object metadata
and eliminates redundant processing of the same code objects across
debugging sessions.
Optimize memory operations by replacing multiple individual structure
copies with single bulk reads for the same data structures. This reduces
the number of memory operations and system calls required to gather
debugging information from the target process.
Update Makefile.pre.in to include Python/remote_debug.h in the headers
list, ensuring that changes to the remote debugging header force proper
recompilation of dependent modules and maintain build consistency across
the codebase.
Also, make the module compatible with the free threading build as an extra :)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 42b25ad4d3)
			
			
This commit is contained in:
		
							parent
							
								
									f68f05cbe3
								
							
						
					
					
						commit
						1822f33b1a
					
				
					 17 changed files with 5397 additions and 4039 deletions
				
			
		|  | @ -2364,6 +2364,8 @@ free_monitoring_data(_PyCoMonitoringData *data) | |||
| static void | ||||
| code_dealloc(PyObject *self) | ||||
| { | ||||
|     PyThreadState *tstate = PyThreadState_GET(); | ||||
|     _Py_atomic_add_uint64(&tstate->interp->_code_object_generation, 1); | ||||
|     PyCodeObject *co = _PyCodeObject_CAST(self); | ||||
|     _PyObject_ResurrectStart(self); | ||||
|     notify_code_watchers(PY_CODE_EVENT_DESTROY, co); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Pablo Galindo Salgado
						Pablo Galindo Salgado