
Does anyone have experience with using large structs in Racket? I tried a simple experiment, declaring a (struct foo (foo-1 foo-2 ... foo-n))
and just running raco make
, and it seems like the compilation phase is superlinear in the number of field structs:


Would this be considered a performance bug (and perhaps be fixed), or should I consider workarounds? (This is for auto-generated code, which is why I have such large structs)

It looks worse than O(n*log(n)) so it’s okay to make an issue.
Which version of Racket was it? And was it plain Racket or the CS version? Do you have a link to the benchmark code?
Anyways - a hash table may be a better fit for the use case.

Not CS; reproduced on Racket 7.3 on macOS and 7.4 on Debian

Although not that old, it’s worth trying the latest versions. Due to the transition to Chez Scheme as back end, it is possible that the structure compilation was revised.

@me1150 Do you need all of the individual field accessor/mutator bindings? If not, using make-struct-type
directly may be a better option, since it gives you a position-based field selector and accessor.

Yes, I do need accessors. Though that should still be O(n)?

Binding is not always liner, but the constant is much much smaller than shown in your graph. The problem doesn’t seem to be in struct
itself, though.

It turns out that all of the time is in setting up struct-field-index
, which can easily be better.

Oh interesting! Thanks for taking the time to investigate. No worries if it’s not a high-priority issue to fix; I suspect not too much real Racket code uses gigantic structs. (I will switch to a different representation, maybe a vector with accessors I synthesize myself.) Let me know if you think I should open a GitHub issue for this.
Also, for a little bit of context, I actually encountered this while writing Rosette code, and then I went back and checked to see if the issue was in Racket or in Rosette. Turns out that both have this superlinear behavior, but Rosette seems to have a worse constant: https://github.com/emina/rosette/issues/147

@moroze has joined the channel

I’ll push a repair that works for 10000 fields in under 1 second on my machine. That at least removes the struct-field-index
setup from being a problem.

I have never heard of this before, thanks for the pointer.

Wow, thank you for the quick fix!

Thank you! I applied the fix to Rosette at https://github.com/emina/rosette/pull/148.

@mflatt is this due to how it’s very expensive to expand syntax-case
with a lot of cases?