mirror of
				https://github.com/Klipper3d/klipper.git
				synced 2025-10-31 02:15:52 +01:00 
			
		
		
		
	garbage_collection: freeze objects on klippy ready (#6794)
This significantly reduces the amount of data in the generation 2 garbage collection bucket from the initial startup of klipper. Signed-off-by: Branden Cash <203336+ammmze@users.noreply.github.com>
This commit is contained in:
		
							
								
								
									
										31
									
								
								klippy/extras/garbage_collection.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								klippy/extras/garbage_collection.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | |||||||
|  | # Garbage collection optimizations | ||||||
|  | # | ||||||
|  | # Copyright (C) 2025  Branden Cash <ammmze@gmail.com> | ||||||
|  | # | ||||||
|  | # This file may be distributed under the terms of the GNU GPLv3 license. | ||||||
|  | import gc | ||||||
|  | import logging | ||||||
|  |  | ||||||
|  | class GarbageCollection: | ||||||
|  |     def __init__(self, config): | ||||||
|  |         self.printer = config.get_printer() | ||||||
|  |         # feature check ... freeze/unfreeze is only available in python 3.7+ | ||||||
|  |         can_freeze = hasattr(gc, 'freeze') and hasattr(gc, 'unfreeze') | ||||||
|  |         if can_freeze: | ||||||
|  |             self.printer.register_event_handler("klippy:ready", | ||||||
|  |                                                 self._handle_ready) | ||||||
|  |             self.printer.register_event_handler("klippy:disconnect", | ||||||
|  |                                                 self._handle_disconnect) | ||||||
|  |  | ||||||
|  |     def _handle_ready(self): | ||||||
|  |         logging.debug("Running full garbage collection and freezing") | ||||||
|  |         for n in range(3): | ||||||
|  |             gc.collect(n) | ||||||
|  |         gc.freeze() | ||||||
|  |  | ||||||
|  |     def _handle_disconnect(self): | ||||||
|  |         logging.debug("Unfreezing garbage collection") | ||||||
|  |         gc.unfreeze() | ||||||
|  |  | ||||||
|  | def load_config(config): | ||||||
|  |     return GarbageCollection(config) | ||||||
| @@ -290,7 +290,7 @@ class ToolHead: | |||||||
|                                             self._handle_shutdown) |                                             self._handle_shutdown) | ||||||
|         # Load some default modules |         # Load some default modules | ||||||
|         modules = ["gcode_move", "homing", "idle_timeout", "statistics", |         modules = ["gcode_move", "homing", "idle_timeout", "statistics", | ||||||
|                    "manual_probe", "tuning_tower"] |                    "manual_probe", "tuning_tower", "garbage_collection"] | ||||||
|         for module_name in modules: |         for module_name in modules: | ||||||
|             self.printer.load_object(config, module_name) |             self.printer.load_object(config, module_name) | ||||||
|     # Print time and flush tracking |     # Print time and flush tracking | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user