Skip to content

Instantly share code, notes, and snippets.

View samspills's full-sized avatar
💜

Sam Pillsworth samspills

💜
View GitHub Profile
@valencik
valencik / JsonlPayloadPipe.scala
Created July 9, 2024 20:19
Elasticsearch Bulk Indexing with a stream of JSON strings
import cats.effect.IO
import fs2.{Pipe, Pull, Stream}
object JsonlPayloadPipe {
/** Builds a pipe that transforms a stream of JSON strings into payloads for the Elasticsearch Bulk
* API. Each input string represents a JSON document to be sent to the Bulk API. The JSONs are
* gathered, interspersed with `delimiter`, and packaged into payload strings up to a maximum
* size of `batchMax` bytes.
*

Understanding Comparative Benchmarks

I'm going to do something that I don't normally do, which is to say I'm going to talk about comparative benchmarks. In general, I try to confine performance discussion to absolute metrics as much as possible, or comparisons to other well-defined neutral reference points. This is precisely why Cats Effect's readme mentions a comparison to a fixed thread pool, rather doing comparisons with other asynchronous runtimes like Akka or ZIO. Comparisons in general devolve very quickly into emotional marketing.

But, just once, today we're going to talk about the emotional marketing. In particular, we're going to look at Cats Effect 3 and ZIO 2. Now, for context, as of this writing ZIO 2 has released their first milestone; they have not released a final 2.0 version. This implies straight off the bat that we're comparing apples to oranges a bit, since Cats Effect 3 has been out and in production for months. However, there has been a post going around which cites various compar

Explaining Miles's Magic

Miles Sabin recently opened a pull request fixing the infamous SI-2712. First off, this is remarkable and, if merged, will make everyone's life enormously easier. This is a bug that a lot of people hit often without even realizing it, and they just assume that either they did something wrong or the compiler is broken in some weird way. It is especially common for users of scalaz or cats.

But that's not what I wanted to write about. What I want to write about is the exact semantics of Miles's fix, because it does impose some very specific assumptions about the way that type constructors work, and understanding those assumptions is the key to getting the most of it his fix.

For starters, here is the sort of thing that SI-2712 affects:

def foo[F[_], A](fa: F[A]): String = fa.toString