How do subscriptions work under the hood?

I’m very curious how subscriptions are managed internally. Specifically, after an update, how is Elm able to assess a batch of Subs and determine which to keep and which to drop, given that function equality if difficult, if not impossible?

I spent a fair amount of time with the Elm source code, however, I could not figure out where to look. Any insight is appreciated.

I haven’t dug into it much but here seems like a good place to get started - it’s where Browser passes the subscriptions function to upon creation.

Ah, yeah, I’ve spent a bunch of time in there but I am finding the source quite difficult to read. Is that JavaScript generated, say, by Haskell?