# Performance of recursive function

**URL:** https://discourse.julialang.org/t/performance-of-recursive-function/83961
**Category:** Performance
**Tags:** recursion
**Created:** [July 8, 2022, 5:19pm UTC](https://discourse.julialang.org/t/performance-of-recursive-function/83961 "2022-07-08T17:19:48Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [July 9, 2022, 7:13am UTC](https://discourse.julialang.org/t/performance-of-recursive-function/83961/8 "2022-07-09T07:13:23Z")

</div>

> [@lawless-m](#):
>
> my point being that recursion is a non-optimal path

Recursion is perfectly fine in performance-sensitive code. In _any_ language (not just Julia), the trick is simply to **enlarge the base case** (so that the recursion overhead is amortized), except in the trivial TCO case that can just be transformed to a loop. See also [Recursive call vs while loop - #18 by stevengj](https://discourse.julialang.org/t/recursive-call-vs-while-loop/7723/18)

---

_[View the full topic](https://discourse.julialang.org/t/performance-of-recursive-function/83961)._
