[ANN] Stringer (v0.3.1) - fast string concatenation


#1

Hi,

I am pleased to announce Stringer, a library for fast string concatenation. Stringer is designed (with tradeoffs) to complement Clojure’s string concat operations.

Stringer’s API contains several macros (so they can not be used as functions) - notably strcat and strfmt that are used frequently. strcat is the Java equivalent of string concatenation + operator. In Java, when you write (“foo” + 42 + “bar”) the Java compiler generates in-line bytecode using java.lang.StringBuilder to concatenate the tokens. strfmt expects the format string (with limited specifier support) to be a literal and applies string interpolation to generate the formatted string much faster than clojure.core/format. The perf benchmark code is included in the repo.

We have used Stringer in production for over 3 years at SAP Concur with only one issue noticed/fixed over 2 years ago. It is usually hard to troubleshoot and optimize the long tail of latency; however, using Stringer has led to overall perf improvements in several composite use cases.

Shantanu


#2

Hello!

I’m curious as to how much faster Stringer is, compared to standard Clojure methods, like str and string/join. If you have any benchmarks, that would be interesting!

Teodor


#3

Hi Teodor,

Thanks for the question. Benchmarks are included in the repo and running the benchmarks is quite easy as mentioned here: https://github.com/kumarshantanu/stringer#running-performance-benchmarks

In the included benchmarks, the Stringer version gets faster and faster as you concatenate more and more small tokens. In my raw benchmarks stringer.core/strcat has turned out to be “up to 20 times” faster than clojure.core/str in various use cases. However, I would suggest to use your (realistic) project use cases in the benchmarks. YMMV

Disclaimer: A benchmark may not represent absolute perf gains in your app; however, the relative difference under high concurrency is more likely to be closer to the perf gains in production.

Shantanu


#4

Cool!

I’d consider bragging about that early in the project README, otherwise I think the common reaction would be “Why use this when I have str?”.


#5

I’d consider bragging about that early in the project README, otherwise I think the common reaction would be “Why use this when I have str ?”.

Thanks, not a bad idea - I will think about it. BTW, I covered Stringer in a talk over years ago. The slides (simulating high load with concurrency=40) are here: https://speakerdeck.com/kumarshantanu/performance-optimization-with-code-as-data-in-clojure?slide=8

Shantanu