Live
Black Hat USADark ReadingBlack Hat AsiaAI Business5 AI-powered consulting startups to watchBusiness InsiderWhat Teens Are Doing With Those Role-Playing Chatbots - The New York TimesGoogle News: AIOCSF explained: The shared data language security teams have been missingVentureBeat AIdark ilanlesswrong.comMicrosoft Is Going Multi-Model with Copilot. Does the Enterprise King Win Again? - The Motley FoolGNews AI MicrosoftShow HN: Running local OpenClaw together with remote agents in an open networkHacker NewsA folk musician became a target for AI fakes and a copyright trollThe Verge AIWhat Teens Are Doing With Those Role-Playing ChatbotsNYT TechnologyChicken-Free Egg Whiteslesswrong.comDesktop Canary v2.1.48-canary.35LobeChat ReleasesPlease someone recommend me a good model for Linux Mint + 12 GB RAM + 3 GB VRAM + GTX 1050 setup.Reddit r/LocalLLaMABest Artificial Intelligence Stocks To Add to Your Watchlist - April 4th - MarketBeatGoogle News: AIBlack Hat USADark ReadingBlack Hat AsiaAI Business5 AI-powered consulting startups to watchBusiness InsiderWhat Teens Are Doing With Those Role-Playing Chatbots - The New York TimesGoogle News: AIOCSF explained: The shared data language security teams have been missingVentureBeat AIdark ilanlesswrong.comMicrosoft Is Going Multi-Model with Copilot. Does the Enterprise King Win Again? - The Motley FoolGNews AI MicrosoftShow HN: Running local OpenClaw together with remote agents in an open networkHacker NewsA folk musician became a target for AI fakes and a copyright trollThe Verge AIWhat Teens Are Doing With Those Role-Playing ChatbotsNYT TechnologyChicken-Free Egg Whiteslesswrong.comDesktop Canary v2.1.48-canary.35LobeChat ReleasesPlease someone recommend me a good model for Linux Mint + 12 GB RAM + 3 GB VRAM + GTX 1050 setup.Reddit r/LocalLLaMABest Artificial Intelligence Stocks To Add to Your Watchlist - April 4th - MarketBeatGoogle News: AI
AI NEWS HUBbyEIGENVECTOREigenvector

Stack vs malloc: real-world benchmark shows 2–6x difference

DEV Communityby Yair LengaApril 1, 20261 min read2 views
Source Quiz

<p>Usually, we assume that malloc is fast—and in most cases it is. <br> However, sometimes "reasonable" code can lead to very unreasonable performance.</p> <p>In a previous post, I looked at using stack-based allocation (VLA / fixed-size) for temporary data, and another on estimating available stack space to use it safely.</p> <p>This time I wanted to measure the actual impact in a realistic workload.</p> <h3> Full Article (Medium - no paywall): </h3> <p><a href="https://blog.stackademic.com/temporary-memory-isnt-free-allocation-strategies-and-their-hidden-costs-159247f7f856" rel="noopener noreferrer">Stack vs malloc: real-world benchmark shows 2–6x difference</a></p> <p>I built a benchmark based on a loan portfolio PV calculation, where each loan creates several temporary arrays (thousand

Usually, we assume that malloc is fast—and in most cases it is. However, sometimes "reasonable" code can lead to very unreasonable performance.

In a previous post, I looked at using stack-based allocation (VLA / fixed-size) for temporary data, and another on estimating available stack space to use it safely.

This time I wanted to measure the actual impact in a realistic workload.

Full Article (Medium - no paywall):

Stack vs malloc: real-world benchmark shows 2–6x difference

I built a benchmark based on a loan portfolio PV calculation, where each loan creates several temporary arrays (thousands of elements each). This is fairly typical code-clean, modular, nothing unusual.

I compared:

  • stack allocation (VLA)

  • heap per-loan (malloc/free)

  • heap reuse

  • static (baseline)

Results:

  • stack allocation stays very close to optimal

  • heap per-loan can be ~2.5x slower (glibc) and up to ~6x slower (musl)

  • even optimized allocators show pattern-dependent behavior

The main takeaway for me: allocation cost is usually hidden—but once it's in the hot path, it really matters.

Curious how others approach temporary workspace in performance-sensitive code.

Was this article helpful?

Sign in to highlight and annotate this article

AI
Ask AI about this article
Powered by Eigenvector · full article context loaded
Ready

Conversation starters

Ask anything about this article…

Daily AI Digest

Get the top 5 AI stories delivered to your inbox every morning.

More about

benchmarkavailable

Knowledge Map

Knowledge Map
TopicsEntitiesSource
Stack vs ma…benchmarkavailableDEV Communi…

Connected Articles — Knowledge Graph

This article is connected to other articles through shared AI topics and tags.

Knowledge Graph100 articles · 164 connections
Scroll to zoom · drag to pan · click to open

Discussion

Sign in to join the discussion

No comments yet — be the first to share your thoughts!