I think it would be a good idea if ring (the implementation) would support & enforce returning byte-array
:s.
It seems to be the fastest way to return things out from memory, e.g. Clojure data -> JSON.
NIO-servers can send it as ByteBuffer
and non-NIO can write it directly to a ByteArrayOutputStream with .write
.
… and Jackson (and Jsonista) has optimized path for producing it, no intemediate Strings or Streams.
what do you think @weavejester? I think there was a catch on implementing Protocols for primitive-arrays. Seem to work thou.
ByteBuffer
s are not supported by all NIO servers. The problem with NIO in particular is that many Java NIO servers predate Java’s own NIO classes, so for instance Netty uses its own system (last I looked).
If it’s feasible to extend a protocol to a byte array without issue, then I don’t see any reason not to add this as a body return type.
Oh, didn't know about the Netty non-NIO internals. Anyway, both Aleph & Immutant(alpha) serve over 1M req/sec in the latest TechEmpower JSON test, both with byte-arrays
.
I'll check if it works in all cases and do a PR.