Stop "Awaiting" Everything: The Hidden Cost of Async Python 🐍 Is your Python codebase turning "Red"? In the world of FastAPI and modern web frameworks, we’ve fallen into a trap: the belief that prefixing every function with async makes our code "faster." But if you’re using async for simple logic or CPU-heavy tasks, you might actually be: 1. Adding "Micro-Stalling": Forcing simple logic through the event loop's scheduling machinery actually slows it down. 2. Hogging the Loop: One CPU-bound "async" function can freeze your entire server. 3, Increasing Cognitive Load: When everything is awaitable, nothing stands out as a genuine I/O bottleneck. I just wrote a deep dive on why "Sync" is often the superior choice for internal logic, data science, and simple utility functions. Check out the full breakdown here:
Async Python: Hidden Costs and When to Choose Sync
More Relevant Posts
-
Clean code isn't clever. It's clear. 5 Python patterns every developer should know: 1️⃣ Flatten nested list: flat = [x for sub in nested for x in sub] 2️⃣ Merge dicts (Python 3.9+): merged = dict_a | dict_b 3️⃣ Most frequent item: max(set(lst), key=lst.count) 4️⃣ Swap variables: a, b = b, a 5️⃣ Read + strip file lines: lines = [l.strip() for l in open("file.txt")] --------------- These aren't tricks. They're idiomatic Python. When your code communicates intent: ✅ Reviews go faster ✅ Bugs surface sooner ✅ Onboarding is smoother Write for the developer reading it at 2am before a deployment. That developer is usually you. #Python #CleanCode #Programming #CodingTips #SoftwareEngineering
To view or add a comment, sign in
-
-
If your Python scripts are making 50 API calls, synchronous code spends most of its time waiting around doing absolutely nothing. Suresh Vina has written an intro to async Python using a simple analogy: boiling a kettle and making toast at the same time. Sync code does one, then the other. Async runs both concurrently. Same two tasks: 5 seconds sync, 3 seconds async. It’s not a big deal when making breakfast. But scale that concept across dozens of API calls and the difference adds up. The Infrahub Python SDK supports both sync and async natively. Switching between them is simple. Suresh walks through the core concepts, shows side-by-side code examples, and builds up to running the same operation across multiple sites concurrently. If async Python has been sitting on your "I should learn that someday" list, now’s your chance to *get up to speed*. (See what we did there? 😉) Link in comments 👇
To view or add a comment, sign in
-
-
🚀 Python 3.14 Level Up: UUIDv7 is here! If you're still using uuid4() for your database keys, you’re fragmenting your indexes. Random IDs = slow writes as your DB grows. 📉 The Fix: UUIDv7 (Now native in Python 3.14!) It’s time-ordered. It sorts naturally. It keeps your database fast. ❌ The Old (Random): id = uuid.uuid4() # Great, but kills DB performance at scale. ✅ The New (Ordered): id = uuid.uuid7() # Fast, sortable, and production-ready. Why?? * Better DB Performance: Sequential inserts = happy B-Trees. * No more shutil: pathlib now has .copy() and .move() too! Are you upgrading to 3.14 for the speed, or staying on 3.12 for the stability? 👇 #Python #CleanCode #Backend #SoftwareEngineering #Databases
To view or add a comment, sign in
-
-
🚀 Built a Python tool that transfers code via QR codes! Introducing PyQR Generator — a desktop app that converts any .py file into scannable QR codes you can read directly on your phone. Here's what it does: → Load any Python file → Generates multiple QR codes (chunks) for large files → Scan each QR with your phone to view the raw code → Copy and use it anywhere — no internet, no USB needed! Built with Python + qrcode — 100% offline and open source. Sometimes the simplest ideas solve real problems. 💡 #Python #Automation #BuildInPublic #QRCode #OpenSource #PythonDeveloper
To view or add a comment, sign in
-
-
Your users are waiting. And leaving. Because your response takes too long. You send everything at once. Big mistake. Django has a hidden weapon: StreamingHttpResponse. Instead of waiting… It sends data in chunks. User sees data instantly ⚡ No loading pain. No frustration. Use it when: → Large files → Real-time output → Slow processing Stop making users wait. Stream it. #Django #Python #WebDevelopment #BackendDevelopment #DjangoTips
To view or add a comment, sign in
-
Had some more fun today with tweaking hyperlight-sandbox VM's. I am now down to ~1ms execution for Python and JavaScript Wasm components in a VM 🎉. But that isn't all... Someone pointed me to pydantic/monty(https://lnkd.in/gpTdBCsB). So, naturally, I compiled it to wasm and put it in Hyperlight-sandbox and I am seeing speeds at coming in at ~0.4 ms 🏎️ That's 500µs. Executing python, in a VM, in wasm 🤯 Obviously, there are limitations in what kind of python code can be run (see monty's docs) but it but if that is all you need then wow!
To view or add a comment, sign in
-
Coming from Go, Python's type system felt loose to me at first. No compile step. No enforcement. Just... hints. But the more I dig in, the more I appreciate tools like `NewType` and `Literal`. In Go, the compiler stops you from mixing up types that share the same underlying type. Python can do something similar — not at runtime, but statically with Mypy. ```python from typing import NewType, Literal UserID = NewType("UserID", int) ProductID = NewType("ProductID", int) # Mypy catches this — both are ints, but they're not the same type process_order(ProductID(1), UserID(2)) # ❌ LogLevel = Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] # Mypy catches this too set_log_level("WRONG") # ❌ ``` The discipline is on you to run the linter. But once you do, you get a surprisingly Go-like experience — catching swapped IDs and invalid strings before they ever hit production. Python's type system isn't weak. It's just opt-in. #Python #Go #TypeSafety #BackendEngineering #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚀 Built a PDF Text Extractor using Python & Streamlit! I often needed a quick way to extract text from PDFs without heavy software. So, I built one myself. 📄 Upload any PDF, and it instantly extracts all the text from every page — clean and simple. ⚙️ The main challenge was handling multi-page PDFs accurately across different formats using PyPDF2. 🛠️ Tech Stack: •Python 3.11.9 • Streamlit • PyPDF2 🔗 GitHub: https://lnkd.in/gvFFf2yA Would love your feedback and suggestions! 🙌 #Python #Streamlit #OpenSource #PythonDeveloper
To view or add a comment, sign in
-
I’ve published my first technical article: a walkthrough of the SOLID principles—with Python examples. It started as “I’ve heard these letters everywhere—what do they actually mean in code?” Turning that into something concrete helped me more than skimming another diagram. In the post I break things down into bite-sized pieces, including: • Single Responsibility: One job per module—easier to reason about and change. • Open/Closed: Extend behavior without rewriting existing code. • Liskov Substitution: Subtypes that don’t break expectations. • Interface Segregation: Small, focused contracts instead of fat interfaces. • Dependency Inversion: Depend on abstractions, not concrete details. Beyond the theory, each section includes short Python snippets so the ideas map to something you can run and tweak—not just memorize. The full post is here: https://lnkd.in/gFXSE4d9 #SoftwareEngineering #SOLID #Python #CleanCode #OOP #DesignPatterns
To view or add a comment, sign in
-
Python scope is one of those topics that separates developers who debug fast from those who don't. The language gives you no warning when a variable resolves to an unexpected value. It simply executes, returns a result, and moves on. Tracking down the source of that behaviour - without a solid mental model of how Python resolves names - can cost hours. The LEGB rule isn't complicated. But it's rarely taught with the depth it deserves. I wrote a free guide to change that: → How Python's name resolution actually works under the hood → The LEGB lookup chain with concrete, practical examples → Enclosing scopes and closure behaviour explained clearly → When global and nonlocal are appropriate - and when they signal a design problem → The scope patterns most likely to introduce silent bugs in real codebases Download it free: https://lnkd.in/djp6HJdD #Python #SoftwareEngineering #PythonDevelopment #BackendDevelopment
To view or add a comment, sign in
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
Great article. Interesting approach 👍