# Where to start with optimizing Racket programs?

**URL:** <https://racket.discourse.group/t/where-to-start-with-optimizing-racket-programs/2634>\
**Category:** Questions & Answers\
**Created:** [January 2, 2024, 12:56am UTC](https://racket.discourse.group/t/where-to-start-with-optimizing-racket-programs/2634 "2024-01-02T00:56:27Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![samth](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/samth/32/3_2.png) [@samth](https://racket.discourse.group/u/samth)\
**Post date:** [January 9, 2024, 4:40pm UTC](https://racket.discourse.group/t/where-to-start-with-optimizing-racket-programs/2634/21 "2024-01-09T16:40:40Z")

</div>

I will say I use the profiler a lot when optimizing. There are two big challenges when using the profiler:

1. It doesn't tell you about the internals of runtime operations (which can be cheap like `vector-ref` or expensive like `local-expand`).
2. It can't tell you about costs that are internal to the runtime, like allocation, garbage collection, or chaperone wrappers. Different tools are needed for that.

---

<div class="post-metadata">

**Author:** ![robby](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/robby/32/7_2.png) [@robby](https://racket.discourse.group/u/robby)\
**Post date:** [January 9, 2024, 7:23pm UTC](https://racket.discourse.group/t/where-to-start-with-optimizing-racket-programs/2634/22 "2024-01-09T19:23:04Z")

</div>

I agree with @samth; the profiler is the first thing I reach for when trying to understand some bad performance. It has limitations but sometimes it just delivers the answer.

---

<div class="post-metadata">

**Author:** ![nikhilm](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@nikhilm](https://racket.discourse.group/u/nikhilm)\
**Post date:** [January 9, 2024, 7:42pm UTC](https://racket.discourse.group/t/where-to-start-with-optimizing-racket-programs/2634/23 "2024-01-09T19:42:34Z")

</div>

I understand a bunch of this is likely tacit knowledge, but putting together some non-exhaustive list of such expensive operations in the documentation would be very helpful!

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [January 9, 2024, 8:13pm UTC](https://racket.discourse.group/t/where-to-start-with-optimizing-racket-programs/2634/24 "2024-01-09T20:13:24Z")

</div>

On Jan 9, 2024, at 10:15 AM, Greg Hendershott via Racket Discourse [notifications@racket.discoursemail.com](mailto:notifications@racket.discoursemail.com) wrote that “[a]nother factor is the Racket community of tool users and tool improving contributors is some orders of magnitude smaller than say Python.”

That’s precisely it. I reach for the profiler extensively once or twice a year. We just published another paper on the profiler, on using it on a large number of cases (automatically). If someone wants to join Ben and/or Christos in tackling the profiler and improving it, please let them know.

---

<div class="post-metadata">

**Author:** ![greghendershott](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/greghendershott/32/98_2.png) [@greghendershott](https://racket.discourse.group/u/greghendershott)\
**Post date:** [January 9, 2024, 8:23pm UTC](https://racket.discourse.group/t/where-to-start-with-optimizing-racket-programs/2634/25 "2024-01-09T20:23:11Z")

</div>

Although it's not exactly what you're asking for, there are some tips sprinkled throughout the [Performance](https://docs.racket-lang.org/guide/performance.html) section of the Guide.

---

<div class="post-metadata">

**Author:** ![samth](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/samth/32/3_2.png) [@samth](https://racket.discourse.group/u/samth)\
**Post date:** [January 9, 2024, 8:41pm UTC](https://racket.discourse.group/t/where-to-start-with-optimizing-racket-programs/2634/26 "2024-01-09T20:41:47Z")

</div>

I don't think there's anything useful to say about most of those; `directory-list` is slower than `open-input-file` is slower than `hash-ref` is slower than `vector-ref` for the obvious reasons. The latter two do say something about their complexity.

[Previous page](https://racket.discourse.group/t/where-to-start-with-optimizing-racket-programs/2634.md?page=1)
