# The Hidden Performance Trap When Mixing std::function and copyable_function

Original title: Interconverting std::function with copyable_function

> Hacker News story 49065540 · language: en · submitted 2026-07-27
> Web version: https://zeli.app/story/49065540
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 18 · by [jandeboevrie](<https://news.ycombinator.com/user?id=jandeboevrie>) · 💬 0
[original](<https://quuxplusone.github.io/blog/2026/07/26/function-explosion/>) · [HN discussion](<https://news.ycombinator.com/item?id=49065540>)

## Summary

I discovered a critical performance pitfall in C++26 where interconverting std::function and std::copyable_function creates a growing chain of callables. This 'logical memory leak' causes invocation latency to increase linearly with every conversion, even if the underlying logic remains unchanged. While libstdc++ currently exhibits this behavior, I advise developers to avoid mixing these types in brown-field codebases to prevent severe runtime degradation.

## Key quote

> Personally I would say that you ought to abandon both, and write your own type-erased callable instead. It takes less than 100 lines!

---

## Cite

- Page: https://zeli.app/story/49065540
- Date: 2026-07-27
- Source: quuxplusone.github.io (https://quuxplusone.github.io/blog/2026/07/26/function-explosion/)
- Hacker News: https://news.ycombinator.com/item?id=49065540

## Other languages

- zh: https://zeli.app/zh/story/49065540 · markdown: https://zeli.app/zh/story/49065540.md
