Subject: Constructor created by define-configuration is slow (>25s) when many fields are defined

From: Tomas Volf <[email-masked]>
Date: Mon, 09 Dec 2024 16:13:16 +0100

Hello,

I am writing a configuration for mpv and hit an issue of the generated
constructor (`home-mpv-configuration') is extremely slow.  While the
almost 800 fields is unusually high, initializing the instances of the
record should *not* take almost 30 seconds.  The full file is attached
to this email (as `mpv.scm').

--8<---------------cut here---------------start------------->8---
scheme@(guix-user)> ,use (gnu home services mpv)
scheme@(guix-user)> ,t (and (home-mpv-configuration (global (mpv-profile-configuration (fullscreen #t)))) #t)                                                                                  
$1 = #t
;; 29.615315s real time, 50.896973s run time.  24.031723s spent in GC.
--8<---------------cut here---------------end--------------->8---

Interestingly, profiling does not give us anything useful:

--8<---------------cut here---------------start------------->8---
scheme@(guix-user)> ,pr (and (home-mpv-configuration (global (mpv-profile-configuration (fullscreen #t)))) #t)                                                                                 
No samples recorded.
--8<---------------cut here---------------end--------------->8---

I also tried to remove all my custom sanitizers, to make sure the issue
is not in my code, but that did not help.

I took a short look, but code of both the define-configuration and of
Guix records is complex, full of syntax magic and I did not have any
luck trying to debug it myself.  Hence this report.

Have a nice day,
Tomas

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.