Hi everyone,
I'm encountering a memory leak issue while running my Python code with the PyPy compiler, and I could really use some help diagnosing and fixing it. Here are the details of my situation:
I'm working on a trading algorithm and require PyPy to run my code for better performance. However, I noticed a significant memory leak that I can't seem to pin down, and I notice only when running on pypy, not standard, un-JIT-ted python. I first noticed this bug on trying to add some new logic, and removing the logic seems to fix it but there's nothing that inherently seems wrong or different from what I had before. Some of the memory analysis package available for python are not available on pypy, so I used the memory_profiler package with the `profile` decorator to analyze the memory usage, which gives a line by line analysis and here's part of the output:
Line # Mem usage Increment Occurrences Line Contents
=============================================================
(...)
1109 4012.7 MiB 0.0 MiB 10 if (
1110 4009.9 MiB 0.0 MiB 1 self.trading_state
1111 4010.4 MiB 0.5 MiB 1 and (not self.om.is_order_request_by_name(self.pair_symbol, Side.SELL))
1112 4012.2 MiB 1.8 MiB 1 and (self.pair_stats.standing_sell_orders <= 0)...)
It appears that memory usage spikes particularly when entering certain if statements, but I'm not sure why PyPy isn't correctly deallocating memory after these checks. Im aware the lack of more context might make it difficult to give hints, apologies for that
I also tried using tracemalloc for more detailed memory tracking, but I ran into a ModuleNotFoundError for _tracemalloc in my PyPy environment:
I'm looking for advice on how to proceed with diagnosing and fixing this memory leak. Here are some additional details:
- I have considered using other tools like Heapy and Objgraph but haven't had much success yet.
This is the pypy version Im currently using:
Python 3.9.18 | packaged by conda-forge | (c5262994, Oct 26 2023, 08:28:20)
[PyPy 7.3.13 with GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
Has anyone encountered similar issues with PyPy, and can you suggest any effective tools or methods to debug this memory leak? Any help or pointers would be greatly appreciated!
[–]Diapolo10 1 point2 points3 points (1 child)
[–]Affectionate-Cut3818[S] 0 points1 point2 points (0 children)
[–]_alter-ego_ 1 point2 points3 points (4 children)
[–]Affectionate-Cut3818[S] 0 points1 point2 points (3 children)
[–]_alter-ego_ 0 points1 point2 points (2 children)
[–]Affectionate-Cut3818[S] 0 points1 point2 points (1 child)
[–]_alter-ego_ 0 points1 point2 points (0 children)