used @rbjorklin addition of webmachine (cohttp) to add opium (master commit with httpaf) as well
(I’ve filtered fastify for JS, giraffe for F# and aspcore for C#)
here’s the implementation:
it uses opium (master commit with httpaf), caqti with ppx_rapper, yojson, tyxml
At first glance there doesn’t appear to be anything super wrong with it, but the performance is not really good compared to JS. Am I doing anything wrong, or should I just accept that this is the performance?
Summary (opium is opium running as a single process, opium-haproxy behind a proxy, which is not super fair for the comparison with JS, which is simply forking a process)
JSON serialization:
with a reverse proxy - 2.7x slower than JS forking processes, 5x slower than F# and 8.6x slower than C#
Single query:
with a reverse proxy - 1.3x faster than JS, 1.74x slower than C# Dapper (~OCaml’s Rapper in terms of API) and 1.3x slower than C# with a full ORM - Entity Framework
Multiple queries:
with a reverse proxy - 2x faster than JS, about the same speed as (with Kestrel) C# Dapper and 1.3x faster than C# Entity Framework
Fortunes:
(includes getting data from a DB, adding a record, ordering the new list and then rendering HTML with tyxml)
1.14x slower than JS, 1.7x slower than dapper F# and C#
Data updates:
(not all implementations are equal - some dapper implementations batch the updates, the OCaml and JS do not)
2.6x faster than JS (either JS’s postgres driver is not really good or a reverse proxy helps a lot), 1.1x slower than C# with entity framework orm
Plaintext:
pretty sure there is something wrong, though, not much to implement wrong in these 3 lines of code:
so I will use webmachine for comparison in this test - 4x slower than JS, 20x slower than F#, 10x slower than C#
since the post was long - to ask my question again - even with a reverse proxy, running multiple processes the performance is pretty close to JS;
Am I doing something wrong, how can I get better performance? Or does the better native performance gain disappear when a VM has a chance to optimize code paths?