All Projects → plokhotnyuk → Fast String Interpolator

plokhotnyuk / Fast String Interpolator

Licence: apache-2.0
Scala macro that generates ultra-fast string interpolators.

Programming Languages

scala
5932 projects
macro
33 projects

Projects that are alternatives of or similar to Fast String Interpolator

Blis
BLAS-like Library Instantiation Software Framework
Stars: ✭ 859 (+1242.19%)
Mutual labels:  high-performance
Katwebx
An extremely fast static web server and reverse proxy for the modern web.
Stars: ✭ 39 (-39.06%)
Mutual labels:  high-performance
Lambda
LAMBDA – the Local Aligner for Massive Biological DatA
Stars: ✭ 59 (-7.81%)
Mutual labels:  high-performance
Koloboke
Java Collections till the last breadcrumb of memory and performance
Stars: ✭ 909 (+1320.31%)
Mutual labels:  high-performance
Awesome Scalability Toolbox
My opinionated list of products and tools used for high-scalability projects
Stars: ✭ 34 (-46.87%)
Mutual labels:  high-performance
Uvloop
Ultra fast asyncio event loop.
Stars: ✭ 8,246 (+12784.38%)
Mutual labels:  high-performance
Cicada
🚀 Fast lightweight HTTP service framework.
Stars: ✭ 851 (+1229.69%)
Mutual labels:  high-performance
Goods Seckill
高性能电商秒杀解决方案,redis预减库存,消息队列异步下单,订单防重,订单防刷,秒杀接口地址隐藏,数学公式验证码
Stars: ✭ 61 (-4.69%)
Mutual labels:  high-performance
Geatpy
Evolutionary algorithm toolbox and framework with high performance for Python
Stars: ✭ 990 (+1446.88%)
Mutual labels:  high-performance
Edgedb Js
JavaScript bindings for EdgeDB
Stars: ✭ 59 (-7.81%)
Mutual labels:  high-performance
Zeus
A high performance, cross-platform Internet Communication Engine. Developed with native socket API. Aim at handling millions of concurrent connections.
Stars: ✭ 30 (-53.12%)
Mutual labels:  high-performance
Rhashmap
Robin Hood hash map library
Stars: ✭ 33 (-48.44%)
Mutual labels:  high-performance
Geojs
Geo-location lookup API
Stars: ✭ 45 (-29.69%)
Mutual labels:  high-performance
May
rust stackful coroutine library
Stars: ✭ 909 (+1320.31%)
Mutual labels:  high-performance
Erlcass
High-Performance Erlang Cassandra driver based on DataStax cpp-driver
Stars: ✭ 59 (-7.81%)
Mutual labels:  high-performance
Stl.fusion
Get real-time UI updates in Blazor apps and 10-1000x faster API responses with a novel approach to distributed reactive computing. Fusion brings computed observables and automatic dependency tracking from Knockout.js/MobX/Vue to the next level by enabling a single dependency graph span multiple servers and clients, including Blazor apps running in browser.
Stars: ✭ 858 (+1240.63%)
Mutual labels:  high-performance
Tarsbenchmark
benchmark tool for tars/http service
Stars: ✭ 41 (-35.94%)
Mutual labels:  high-performance
Go Workerpool
Worker pool implementation
Stars: ✭ 62 (-3.12%)
Mutual labels:  high-performance
Netmap Tutorial
Netmap tutorial at SIGCOMM 2017 and AsiaBSDCon 2018
Stars: ✭ 60 (-6.25%)
Mutual labels:  high-performance
Radiance
High-Performance BitTorrent Tracker written in C++
Stars: ✭ 46 (-28.12%)
Mutual labels:  high-performance

Fast String Interpolator

Actions Build TravisCI Build Coverage Status Scala Steward Maven Central

Scala macro that generates ultra-fast string interpolators.

Acknowledgments

A general idea and some parts of code was borrowed from a great article "Scala: String Interpolation Performance" by Dmitry Komanov.

Goals, features, and limitations

A high-performance 100% compatible drop-in replacement of simple and raw string interpolators (s"" or raw"" literals).

Currently, it doesn't support formatting string interpolator (f"" literal), however this will probably be added soon.

How to use

Add the library to a dependency list:

libraryDependencies += "com.github.plokhotnyuk.fsi" %% "fsi-macros" % "0.6.1"

Add import and replace prefix s by fs (or for a raw string interpolator raw by fraw):

import com.github.plokhotnyuk.fsi._

val host = "company.com"
val path = "blog"
fs"http://$host/$path"
fraw"http://$host/$path"

That's it! You have got ~1.5x speed up in runtime and ~4x less usage of heap memory comparing to standard interpolators which come with 2.12.8 version of Scala compiler.

Also, it is more efficient than a simple concatenation of strings by the + operator or using string builders for that.

Check for benchmark results where the fast string interpolator compared with standard Scala interpolators, 3rd-party interpolators, Scala/Java string builders, and a string concatenation using JDK 8 and Scala 2.12.5:

  • fInterpolator - standard string interpolator with formatting
  • fastInterpolator - the fastring interpolator
  • frawInterpolator - fast string interpolator replacement for raw string interpolator
  • fsInterpolator - fast string interpolator replacement for simple string interpolator
  • javaStringBuilder - java.lang.StringBuilder
  • pInterpolator - the perfolation interpolator
  • rawInterpolator - standard raw string interpolator
  • sInterpolator - standard simple string interpolator
  • scalaStringBuilder - scala.collection.mutable.StringBuilder
  • scalaStringConcatenation - + operand for strings

Throughput

Heap Usage

NOTE: Numbers can vary depending on use case, payload, JDK, and Scala versions. For cases, like templating with lot of nested cycles, please consider using of fastring or string builders immediately.

Results of benchmarks which compare performance of Fast String Interpolator with other alternatives for different cases of simple and nested loop usage, and for different versions of JDK and Scala.

How it works

Let we have defined functions: def f(): Int and def g(): Double, then in compile-time for fs"a${f()}bb${g()}" the following code will be generated:

{
  val fresh$macro$1: Int = f();
  val fresh$macro$2: Double = g();
  com.github.plokhotnyuk.fsi.`package`.stringBuilder().append('a').append(fresh$macro$1).append("bb").append(fresh$macro$2).toString();
}: String

You can check this by adding a compiler option: scalacOptions += "-Ymacro-debug-lite".

In this code com.github.plokhotnyuk.fsi.`package`.stringBuilder() stands for getting a preallocated instance of java.lang.StringBuilder from the thread-local pool.

By default a buffer capacity of all created java.lang.StringBuilder instances is 16384 characters (32Kb). If limit is reached buffer size grows to ensure that whole string can fit in it. However next retrieval from the pool a new java.lang.StringBuilder instance will be allocated with the default size of the buffer and returned to avoid exhausting of Java heap. So if you want to work with longer strings without reallocations then set a greater value for the following JVM system property: com.github.plokhotnyuk.fsi.buffer.size.

How to contribute

Build

To compile, run tests, check coverage, and check binary compatibility for different Scala versions use a command:

sbt ++2.11.12 clean coverage test coverageReport mimaReportBinaryIssues
sbt ++2.12.8 clean coverage test coverageReport mimaReportBinaryIssues

Run benchmarks

Feel free to modify benchmarks and check how it works on your payload, JDK, and Scala versions.

To see throughput with allocation rate for different approaches of string concatenation run benchmarks with GC profiler for a specified JDK and Scala versions using the following command:

sbt -java-home /usr/lib/jvm/jdk1.8.0 -no-colors ++2.12.8 clean 'fsi-benchmark-core/jmh:run -jvm /usr/lib/jvm/jdk-11/bin/java -prof gc -rf json -rff jdk-11_scala-2.12.8.json .*'

It will save benchmark report in a specified JSON file.

Results that are stored in JSON can be easy plotted in JMH Visualizer by drugging & dropping of your file to the drop zone or using the source parameter with an HTTP link to your file in the URL like here.

Publish locally

Publish to the local Ivy repo:

sbt +publishLocal

Publish to the local Maven repo:

sbt +publishM2

Release

For version numbering use Recommended Versioning Scheme that is used in the Scala ecosystem.

Double check binary and source compatibility (including behavior) and run release command (credentials required):

sbt release
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].