github / semantic

Parsing, analyzing, and comparing source code across many languages
8.94k stars 454 forks source link

Give Parse effect the ability to parse concurrently #615

Open patrickt opened 4 years ago

patrickt commented 4 years ago

Now that #614 is taken care of (or will be soon), we need to reexamine our approach to concurrency.

The simplest big win is to change

data Parse (m :: Type -> Type) k where
  Parse :: Parser term -> Blob -> Parse m term

to

data Parse (m :: Type -> Type) k where
  Parse :: Traversable t => Parser term -> t Blob -> Parse m term

Because Parse ends up running an IO action, we can use mapConcurrently to perform said operations. Unfortunately, this requires a bit of plumbing; I’ve taken two swings at this and whiffed. Now that alacarte syntax is gone, this might be a good move.

patrickt commented 4 years ago

I tried doing this and observed a significant performance regression with keras/keras. This makes me very sad.

patrickt commented 4 years ago

Okay I see what the problem is here: forConcurrently is not a good solution for us: it does a lot of work per-invocation (creating an MVar and calling fork for every item in the provided list). We should do something like set up some concurrent queues.