Live
Black Hat USADark ReadingBlack Hat AsiaAI BusinessAssessing Marvell Technology (MRVL) After Nvidia’s US$2b AI Partnership And Connectivity Push - simplywall.stGNews AI NVIDIADutchess to host artificial intelligence summit at Marist in Poughkeepsie - Daily FreemanGoogle News: AIAnthropic’s Catastrophic Leak May Have Just Handed China the Blueprints to Claude Al - TipRanksGoogle News: ClaudeOpenAI's Fidji Simo Is Taking Medical Leave Amid an Executive Shake-UpWired AIMeta's AI push is reshaping how work gets done inside the companyBusiness InsiderOpenAI's Fidji Simo Is Taking Medical Leave Amid an Executive Shake-Up - WIREDGoogle News: OpenAIFirst time NeurIPS. How different is it from low-ranked conferences? [D]Reddit r/MachineLearningAI & Tech brief: Ireland ascendant - The Washington PostGNews AI EUPeople would rather have an Amazon warehouse in their backyard than a data centerTechCrunch AITake-Two lays off its head of AI and several team members just two months after the CEO said it was embracing Gen AI - TweakTownGoogle News: Generative AIOpenAI Buys TBPN Tech Talk Show for Enterprise Client Outreach - News and Statistics - IndexBoxGoogle News: OpenAILenovo Legion Go 2 suddenly costs $650 more as RAMageddon lays waste to gaming hardwareThe VergeBlack Hat USADark ReadingBlack Hat AsiaAI BusinessAssessing Marvell Technology (MRVL) After Nvidia’s US$2b AI Partnership And Connectivity Push - simplywall.stGNews AI NVIDIADutchess to host artificial intelligence summit at Marist in Poughkeepsie - Daily FreemanGoogle News: AIAnthropic’s Catastrophic Leak May Have Just Handed China the Blueprints to Claude Al - TipRanksGoogle News: ClaudeOpenAI's Fidji Simo Is Taking Medical Leave Amid an Executive Shake-UpWired AIMeta's AI push is reshaping how work gets done inside the companyBusiness InsiderOpenAI's Fidji Simo Is Taking Medical Leave Amid an Executive Shake-Up - WIREDGoogle News: OpenAIFirst time NeurIPS. How different is it from low-ranked conferences? [D]Reddit r/MachineLearningAI & Tech brief: Ireland ascendant - The Washington PostGNews AI EUPeople would rather have an Amazon warehouse in their backyard than a data centerTechCrunch AITake-Two lays off its head of AI and several team members just two months after the CEO said it was embracing Gen AI - TweakTownGoogle News: Generative AIOpenAI Buys TBPN Tech Talk Show for Enterprise Client Outreach - News and Statistics - IndexBoxGoogle News: OpenAILenovo Legion Go 2 suddenly costs $650 more as RAMageddon lays waste to gaming hardwareThe Verge
AI NEWS HUBbyEIGENVECTOREigenvector

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

DEV Communityby Yair LengaApril 1, 20261 min read1 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 · 145 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!