# Only-in in a require statement

**URL:** <https://racket.discourse.group/t/only-in-in-a-require-statement/2751>\
**Category:** Questions & Answers\
**Created:** [February 28, 2024, 5:59pm UTC](https://racket.discourse.group/t/only-in-in-a-require-statement/2751 "2024-02-28T17:59:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![matteo-daddio](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/matteo-daddio/32/1245_2.png) [@matteo-daddio](https://racket.discourse.group/u/matteo-daddio)\
**Post date:** [February 28, 2024, 5:59pm UTC](https://racket.discourse.group/t/only-in-in-a-require-statement/2751/1 "2024-02-28T17:59:08Z")

</div>

Hello,  
using _only-in_ in a _require_ statement can improve the memory footprint? It’s a good practice?

Matteo

---

<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:** [February 29, 2024, 7:56pm UTC](https://racket.discourse.group/t/only-in-in-a-require-statement/2751/2 "2024-02-29T19:56:17Z")

</div>

My understanding: The granularity is modules.

By using `require` at all you pay the speed and space cost for requiring the entire module -- as well as all the modules it transitively requires, that aren't already required.

This can be significant, for example `racket` vs. just `racket/base`.

Clauses like `only-in` don't change this; they're not an optimization for space or speed (the entire module(s) will still be instantiated). Instead they're about visibility: You don't want to expose _all_ the exported definitions, just some. You want to be explicit that you're importing the module to get what from it, exactly.

One example: If you have some local definition of `foo`, and require a module `m` just to use its exported `bar`, great, but someday `m` could decide to start exporting something called `foo`, too. Strictly speaking, exporting new things breaks backward compatibility. Clauses like `only-in`, `prefix-in`, `rename-in` are ways for importers to handle that, as well as potentially make the code and intent clearer.
