`RowList` iteration seems to be relatively slow

I have this trivial class which instances only iterate over a RowList

class IterProps (rl ∷ RowList)

instance iterPropsCons ∷ (IterProps t) ⇒ IterProps (Cons n a t)

instance iterPropsNil ∷ IterProps Nil

iter ∷ ∀ r rl. RowToList r rl ⇒ IterProps rl ⇒ RProxy r → Unit
iter _ = unit

When I run iter on a row with a 200 fields compilation takes 800 ms (where the baseline compilation without iter usage takes around 25 ms) on my machine using purs-0.13.8. The full live example can be found here:

https://try.purescript.org/?gist=849034ed00d238f63c4099f8c93b7280

This seems to have possible practical implications. For example:

  • In react-basic we can find rows longer than 120 fields. Any typelevel transformation like handling untagged unions with tools like one-of seems to be an overkill for the project.
  • We can easily imagine large rows in the case of a database tables which will for sure affect the coding experience in the case of libs like selda which uses heavily RowList machinery.
3 Likes

P.S.

When I iterate twenty times over a row of length ten it takes around 80 - 100 ms on the same machine.

Is it worth an issue and discussion? Should I move it from here to the github PS repo?

I think this is expected at the moment; I think most things involving type classes are slow. RowList is especially slow because you have to do a lot of solving when you’re using them. I think it might be best to wait until someone has a concrete strategy in mind for addressing this before opening an issue on github, as otherwise I think it will probably just sit there.

2 Likes