I deleted code and my CPU usage dropped by 90%. . . . . I recently spent time optimizing a PDF processing microservice (FastAPI + PyMuPDF) and stumbled upon a surprising performance killer: 'gc.collect()'. - By simply removing manual garbage collection calls, my CPU utilization plummeted from spikes of 80%+ down to a steady 5-6%. -In Python, we often get tempted to manually call gc.collect() when handling mem heavy tasks (like splitting large PDFs) to "help" the system. However, this often causes more harm than good: -Every time you call gc.collect(), Python pauses your execution to traverse every object in memory. In a high-concurrency environment, this creates massive CPU churn. The Takeaway: - Trust the runtime. If you feel the need to manually trigger the GC, it’s usually a sign that your object management needs a refactor, not that the collector is being "lazy." Sometimes, the best code is the code you delete. #Python #SoftwareEngineering #Performance #FastAPI #CleanCode #BackendDevelopment
Removing gc.collect() Boosts CPU Performance by 90%
More Relevant Posts
-
Visualizing Multithreading: From Race Conditions to Thread Safety 🧵💻 I’ve always believed that the best way to master complex Operating System concepts is to build them from scratch. I recently developed a Multithreading Task Manager in Python to simulate how modern OSs handle concurrent tasks. Key features I implemented: ✅ Thread Lifecycle Simulation: Visualizing threads moving from New → Ready → Running → Terminated. ✅ Race Condition Demo: Showing how data corruption occurs without proper locking mechanisms. ✅ Mutex Locks: Using threading.Lock() to ensure critical sections are protected. ✅ Producer-Consumer Pattern: Implementing a thread-safe Task Queue. Building this helped me bridge the gap between theoretical OS concepts and practical, thread-safe Python code. Check out the demo below! 👇 #Python #Multithreading #OperatingSystems #ComputerScience #SoftwareEngineering #BackendDevelopment #Concurrency
To view or add a comment, sign in
-
🚀 Mg 0.6.0 is out. This release brings Mg up to date with SysML v2 (0.57.0, 2026-02), aligning with the latest Pilot Implementation and pushing the ecosystem forward. We’ve also upgraded to Python 3.13.12, ensuring better compatibility with modern tooling. Most notably, Mg now supports MgS expressions—unlocking more expressive, flexible modeling workflows. More details here: https://lnkd.in/e4rjvi8i We’re continuing to expand integration across DOORS Next, Mg, and MgX. Stay tuned. #SysMLv2 #MBSE #SystemsEngineering #Modeling #Python
To view or add a comment, sign in
-
The most dangerous phrase in software is: "But it works on my machine." ⚠️ I decided to eliminate that phrase entirely for my latest project. This video captures the "black box" transformation—using the Nuitka compiler to translate thousands of lines of Python into optimized C code. It’s a tense few minutes watching the machine stitch together ezdxf, win32com, and Tkinter into a single, indestructible executable. The Mystery: Why go through the trouble of a C-level compilation instead of just running a script? Because when a tool hits the production floor, it needs to be more than just "code." It needs to be a professional-grade solution for engineering efficiency. The goal was to take a complex environment and vanish it—leaving behind nothing but a high-performance, standalone tool. The Result: The "Successfully created" message at the end isn't just a build log. It’s the birth of LCPL_Grey_Scaler.exe (v1.1). No Python installation needed. No dependency errors. Just pure, compiled speed. 🚀 #Python #SoftwareEngineering #Automation #CAD #Nuitka #Innovation #CodingLife #Engineering #Deployment
To view or add a comment, sign in
-
I just wrapped up a Student Result Management System built with Python, and I’m excited about the progress. What started as a simple logic exercise quickly turned into a functional tool. Key features I implemented: Data Structures: Used Dictionaries to efficiently map student names to their scores and grades. Control Flow: Applied loops and conditionals to automate grading and result processing. File Handling (The big win!): Integrated .txt file operations so that student data is saved and retrieved even after the program closes. Moving from volatile memory to File Handling felt like a major milestone—it’s the difference between a temporary script and a persistent application. 📂 I’m currently focusing on strengthening my backend fundamentals and building projects that solve small, real-world problems. Next up: Exploring how to structure this more efficiently using Functions or maybe even a CSV format for better data portability! Any tips from the dev community on optimizing file storage in Python? Let me know below! 👇 #Python #CodingJourney #BackendDevelopment #Programming #StudentProject #LearningToCode
To view or add a comment, sign in
-
𝐃𝐚𝐲 𝟗 𝐨𝐟 𝐁𝐮𝐢𝐥𝐝 𝐒𝐜𝐚𝐥𝐚𝐛𝐥𝐞 𝐚𝐧𝐝 𝐄𝐟𝐟𝐢𝐜𝐢𝐞𝐧𝐭 𝐒𝐨𝐥𝐮𝐭𝐢𝐨𝐧𝐬 𝐭𝐨 𝐑𝐞𝐚𝐥-𝐖𝐨𝐫𝐥𝐝 𝐂𝐨𝐝𝐢𝐧𝐠 𝐏𝐫𝐨𝐛𝐥𝐞𝐦𝐬 : 𝐂𝐨𝐧𝐜𝐮𝐫𝐫𝐞𝐧𝐜𝐲 𝐚𝐧𝐝 𝐏𝐚𝐫𝐚𝐥𝐥𝐞𝐥𝐢𝐬𝐦: 𝐈𝐧𝐭𝐫𝐨𝐝𝐮𝐜𝐭𝐢𝐨𝐧 𝐭𝐨 𝐓𝐡𝐫𝐞𝐚𝐝𝐬 𝐚𝐧𝐝 𝐏𝐫𝐨𝐜𝐞𝐬𝐬𝐞𝐬 Diving into concurrency and parallelism this week as we tackle building scalable solutions! Understanding the difference between threads and processes is absolutely crucial. Processes are independent execution environments, each with their own memory space. Threads, on the other hand, exist within a process and share its memory. This distinction leads to important trade-offs. Threads are generally lighter and faster to create, but sharing memory can lead to tricky synchronization issues. Processes are more robust but come with higher overhead. Here's a lesser-known fact: Did you know the Global Interpreter Lock (GIL) in Python (CPython) largely prevents true parallelism for CPU-bound tasks using threads? Multi-processing is often the answer for those scenarios! Which approach – threads or processes – do you find yourself reaching for most often when optimizing for concurrency and why? #Concurrency #Parallelism #Threads #Processes #Python #Coding #SoftwareEngineering #Scalability #Performance
To view or add a comment, sign in
-
-
🚀 Built a Scalable Log Processing System using Python Recently, I worked on a backend-focused project where I designed a system to efficiently process large log files using multiprocessing and streaming techniques. 🔹 Key Highlights: Processed large log files without loading everything into memory Implemented batch-based streaming for better memory efficiency Used multiprocessing (Pool) for parallel execution Designed custom chunking logic for workload distribution Applied MapReduce-style aggregation for results Exported structured output in JSON format 🧠 Architecture: File → Batch → Chunk → Parallel Workers → Aggregation → JSON Output 💡 Key Learnings: Difference between multiprocessing and threading Importance of memory-efficient design Task vs process execution model Impact of data structures (append vs extend) 🔗 GitHub Repo: https://lnkd.in/g4Zc2CFf This project helped me understand how real-world backend systems handle large-scale data processing. #Python #BackendDevelopment #SystemDesign #Multiprocessing #Learning #Projects
To view or add a comment, sign in
-
-
Federated Data Orchestration. Managing tasks across classical GPUs and a networked 51-qubit logical fabric. Skills: Python, Qiskit. https://www.data-t.uk/ae-2 #HPC #BigData #DataT
To view or add a comment, sign in
-
FastAPI just unlocked a massive performance ceiling. 🚀 With the official release of FastAPI 0.136.0 supporting free-threaded Python (No-GIL) , I couldn't just read the changelog—I had to benchmark it. I ran a controlled, head-to-head comparison using identical code and identical hardware: ⚙️ Python 3.12 (GIL) vs. Python 3.13.0t (No-GIL) The result? A ~8x improvement in CPU-bound throughput. Same code. Same API. Zero changes. This is a game-changer for anyone running: 🔹 ML Inference APIs (real-time model serving) 🔹 Data Processing & ETL Workloads 🔹 CPU-Intensive Backend Services Is this the final nail in the coffin for the GIL bottleneck? Curious to hear what the Python backend community thinks. #FastAPI #Python #NoGIL #PerformanceEngineering #BackendDevelopment #Concurrency #MachineLearning
To view or add a comment, sign in
-
-
The Hidden Cost of a Missing Value You start with Employee IDs: 101, 102, 103 After a join: 101.0, 102.0, NaN That .0 isn’t cosmetic—it’s a silent upcast. Under the hood, NumPy-backed systems (like Pandas) require columns to have a fixed dtype for vectorized performance. Standard integers don’t support nulls, but IEEE 754 floating-point does (via NaN). So to accommodate a single missing value, the entire column is upcast to float64. This is a classic leaky abstraction: 1) Very large numbers can lose accuracy when converted to floating point. 2) Memory usage may increase depending on original dtype Modern solutions (Pandas nullable dtypes, Apache Arrow, Polars) solve this using validity bitmasks—keeping integers as integers while tracking nulls separately with a very minimal tradeoffs on compatibility and compute Even “nothing” has a cost in system design. #DataEngineering #Python #SystemDesign
To view or add a comment, sign in
-
Add two numbers without using + or -. I stared at this for a long time before it finally made sense. Sum of Two Integers - LeetCode 371 - Medium This problem has one rule — you cannot use + or - operators. My brain immediately said that is impossible. Addition is addition. How do you add without adding? Then I remembered how addition actually works at the hardware level. When a CPU adds two numbers it does not magically compute the sum. It uses XOR for the sum bits and AND with a left shift for the carry bits. That is literally how circuits work. So I replicated that. XOR of a and b gives the sum without carry. AND of a and b shifted left gives the carry. I keep doing this until there is no carry left. The mask 0xFFFFFFFF handles the edge case of negative numbers in Python since Python integers have infinite precision unlike other languages. What clicked for me: I was thinking like a programmer. This problem forced me to think like a hardware engineer. That perspective shift was everything. Key Learnings 1) XOR as Addition: a ^ b adds two numbers without considering carry. This is exactly how half adder circuits work in real hardware. 2) AND with Left Shift as Carry: (a & b) << 1 computes where the carry needs to go. This is the carry propagation step. 3) Python Mask Handling: Python has infinite precision integers so negative numbers behave differently. The 0xFFFFFFFF mask forces 32 bit behaviour to handle this correctly. Time and Space Complexity Time Complexity: O(1) — At most 32 iterations since integers are 32 bit. Space Complexity: O(1) — Only a few variables used. This problem taught me something no textbook ever did — addition is just XOR and carry in disguise. Did you know this is how your CPU actually adds numbers? Drop your thoughts below 👇 #LeetCode #BitManipulation #Blind75 #SDEPrep #DataStructures #Python #ProblemSolving #CodingJourney #Freshers #AmazonSDE
To view or add a comment, sign in
-
Explore related topics
- How to Refactor Code Thoroughly
- Simple Ways To Improve Code Quality
- How Developers Use Composition in Programming
- Coding Best Practices to Reduce Developer Mistakes
- Importance of Code Deletion in Software Projects
- How to Organize Code to Reduce Cognitive Load
- Building Clean Code Habits for Developers
- Clean Code Practices For Data Science Projects
- How to Improve Code Performance
- Importance of Removing Dead Code in Software Development
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development