# Repl delays, background CPU

**URL:** <https://racket.discourse.group/t/repl-delays-background-cpu/3684>\
**Category:** General\
**Created:** [April 10, 2025, 2:13pm UTC](https://racket.discourse.group/t/repl-delays-background-cpu/3684 "2025-04-10T14:13:40Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![acarrico](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/acarrico/32/2135_2.png) [@acarrico](https://racket.discourse.group/u/acarrico)\
**Post date:** [April 10, 2025, 2:13pm UTC](https://racket.discourse.group/t/repl-delays-background-cpu/3684/1 "2025-04-10T14:13:41Z")

</div>

I've noticed some REPL issues. User perceptible delay and 100%CPU usage (two different issues). See below:

In emacs / racket-mode:

```scheme
racket-mode> (let loop () (define form (read)) (unless (eq? form 'q) (println form) (loop)))

hello
*****delay*****'hello
q

```

In DrRacket:

```scheme
drracket> (let loop () (define form (read)) (unless (eq? form 'q) (println form) (loop)))
hello
*****delay*****'hello
q

```

On the command line:

```scheme
[acarrico@russet terms]$ racket 
Welcome to Racket v8.13 [cs].
> (let loop () (define form (read)) (unless (eq? form 'q) (println form) (loop))
)
hello
*****FAST, no delay*****'hello
hello
'hello
hello
'hello
hello
'hello
q
> 
***laptop fan goes on, .racket-wrapped uses 100% CPU in top****

```

Anyone else have similar issues? I'm on NixOS.

---

<div class="post-metadata">

**Author:** ![acarrico](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/acarrico/32/2135_2.png) [@acarrico](https://racket.discourse.group/u/acarrico)\
**Post date:** [April 10, 2025, 10:05pm UTC](https://racket.discourse.group/t/repl-delays-background-cpu/3684/2 "2025-04-10T22:05:10Z")

</div>

I got a chance to run my test on a Debian machine, also with Racket v8.13:

racket-mode: racket-mode repl under Debian seems responsive.

DrRacket: I replicate the delay issue under Debian

command line: I replicate the command line CPU 100% issue under Debian.

Maybe I'll open an issue since I've seen it on two machines.

---

<div class="post-metadata">

**Author:** ![shhyou](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@shhyou](https://racket.discourse.group/u/shhyou)\
**Post date:** [April 11, 2025, 2:19am UTC](https://racket.discourse.group/t/repl-delays-background-cpu/3684/3 "2025-04-11T02:19:16Z")

</div>

This may be related (but I have no idea why DrRacket would be affected)

> <https://github.com/racket/racket/issues/4964>
>
> \*\*What version of Racket are you using?\*\*
> 8.12.0.14 \[cs\]
> 
> \*\*What program did …you run?\*\*
> 
> \`\`\`
> $ racket
> Welcome to Racket v8.12.0.14 \[cs\].
> \> (read)
> \`\`\`
> 
> At this point, the cpu usage is still normal.
> 
> After typing \`1\` and pressing enter, the interaction becomes:
> 
> \`\`\`
> $ racket
> Welcome to Racket v8.12.0.14 \[cs\].
> \> (read)
> 1
> 1
> \>
> \`\`\`
> 
> with 100% cpu usage
> 
> \*\*What should have happened?\*\*
> 
> Not 100% cpu usage
> 
> \*\*If you got an error message, please include it here.\*\*
> 
> N/A
> 
> \*\*Please include any other relevant details\*\*
> 
> Apple M2

---

<div class="post-metadata">

**Author:** ![acarrico](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/acarrico/32/2135_2.png) [@acarrico](https://racket.discourse.group/u/acarrico)\
**Post date:** [April 11, 2025, 2:39am UTC](https://racket.discourse.group/t/repl-delays-background-cpu/3684/4 "2025-04-11T02:39:10Z")

</div>

Yes. That is one of the issues, also this report:

[Concurrent infinite loops and odd behavior from `read` in REPLs · Issue #4612 · racket/racket · GitHub](https://github.com/racket/racket/issues/4612)

---

<div class="post-metadata">

**Author:** ![acarrico](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/acarrico/32/2135_2.png) [@acarrico](https://racket.discourse.group/u/acarrico)\
**Post date:** [April 11, 2025, 5:40pm UTC](https://racket.discourse.group/t/repl-delays-background-cpu/3684/5 "2025-04-11T17:40:08Z")

</div>

This seems to be a real thing, so discussion has moved to [issue 4612](https://github.com/racket/racket/issues/4612). Greg Hendershott has addressed the delay issue in racket-mode [issue 749](https://github.com/greghendershott/racket-mode/issues/749).

---

<div class="post-metadata">

**Author:** ![acarrico](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/acarrico/32/2135_2.png) [@acarrico](https://racket.discourse.group/u/acarrico)\
**Post date:** [April 28, 2025, 3:03pm UTC](https://racket.discourse.group/t/repl-delays-background-cpu/3684/6 "2025-04-28T15:03:02Z")

</div>

As I mentioned in the racket-mode thread, but should probably mention here for the community. I figured out a great way to run a command loop in emacs. Instead of hitting `F5` to enter the racket-mode repl, run `C-u M-x compile`. This will run your command loop in comint mode, so you get a lot of features for free. Adding the C-u prefix gives two-way prompt style communication with your program. In this mode, the history is your command loop's own history (rather than the Racket repl history), which is a very nice feature to get for free.

---

<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:** [May 2, 2025, 1:59pm UTC](https://racket.discourse.group/t/repl-delays-background-cpu/3684/7 "2025-05-02T13:59:55Z")

</div>

I suppose another possible design would be for the user program's input/output to get its own dedicated UI -- such as a completely different buffer in Emacs.

IIRC DrRacket sort of does this for user program _input_ -- a temporary input box appears -- but the resulting input and all user program _output_ still goes in the interactions pane.

(I actually considered that kind of UX but it seemed impossible to achieve well with a separate front end process in Emacs. For Emacs, I think it would be cleaner to use a dedicated I/O buffer, which could e.g. be put in `comint-mode` as @acarrico said or otherwise customized differently.)

* * *

Some existing precedent for this split is logger output: In command-line Racket, this gets written to stdout -- but in both DrR and Racket Mode, this gets its own UI. Since logger output is async, this is particularly helpful.

Having said that, I've heard from one user who doesn't love the separated logger output. There are tradeoffs. The command line approach, with everything dumped together, can feel more immediate and complete, and regardless of async there is _some_ useful sense of interleaved time-ordering. (And some people may not care that the resulting mix is "hopeless", and the original structure can only be recovered through unreliable regexps).

Maybe the "most correct" UI would use one window/pane, time flowing down, and separate columns for REPL per se, user I/O, logger, etc. That would avoid "hiding" anything, preserve time order, and preserve structure. How _usable_ it would be... idk.

---

<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:** [May 2, 2025, 2:20pm UTC](https://racket.discourse.group/t/repl-delays-background-cpu/3684/8 "2025-05-02T14:20:11Z")

</div>

Ah, this is a nice idea! We didn't consider segregating the user program output from the REPL output! That would have made the implementation simpler too, I believe.

---

<div class="post-metadata">

**Author:** ![LiberalArtist](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/liberalartist/32/151_2.png) [@LiberalArtist](https://racket.discourse.group/u/LiberalArtist)\
**Post date:** [May 2, 2025, 4:09pm UTC](https://racket.discourse.group/t/repl-delays-background-cpu/3684/9 "2025-05-02T16:09:23Z")

</div>

You do give them different colors!

---

<div class="post-metadata">

**Author:** ![acarrico](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/acarrico/32/2135_2.png) [@acarrico](https://racket.discourse.group/u/acarrico)\
**Post date:** [May 3, 2025, 2:40am UTC](https://racket.discourse.group/t/repl-delays-background-cpu/3684/10 "2025-05-03T02:40:21Z")

</div>

> [@greghendershott](#):
>
> I suppose another possible design would be for the user program's input/output to get its own dedicated UI -- such as a completely different buffer in Emacs.

```scheme
Welcome to Racket v8.13 [cs].
————— run main.rkt —————
main.rkt> (display "hello> ")
main.rkt> (read)
'#(1 2 3)
main.rkt> 
————— stdio ————————
hello> #(1 2 3)

————— stderr ————————
—————————————————————

```

Bonus points for raw mode. But actually just choosing among racket-repl or comint is working pretty well for me. Life would compete if I figured out how to launch into term-mode if I needed raw i/o.
