SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
SCALA JSON FEATURES AND
PERFORMANCES
John Nestor- 47 Degrees
nestor@persist.com
Dragos Manolescu
dam@micro-workflow.com
https://github.com/47deg/json-perf
47deg.com 1
47deg.com
DISCLAIMER
• Best effort attempt to measure performance and
describe features.
• Corrections always appreciated.
• Also let us know any Json parsers we missed.
47deg.com 2
47deg.com
• There are lots of Scala Json parsers
• You can also use Java Json parsers in Scala
• How to Choose:
• Performance
• Features
• API
• Support (will not be abandoned)
• License (most are Apache 2)
SCALA JSON
3
47deg.com
SCALA (2.11) JSON PARSERS
Parser URL Version Language
Persist Json https://github.com/nestorpersist/json 1.1.0 Scala
Rojoma https://github.com/rjmac/rojoma-json 3.3.0 Scala
Jackson
http://wiki.fasterxml.com/
JacksonHome
2.5.3 Scala/Java
Spray Json https://github.com/spray/spray-json 1.3.2 Scala
Lift Json
https://github.com/lift/lift/tree/master/
framework/lift-base/lift-json/
2.6.2 Scala
Twitter Json https://github.com/stevej/scala-json NA Scala
Scala Library
https://github.com/scala/scala-parser-
combinators
1.0.4 Scala
Play Json
https://www.playframework.com/
documentation/2.0/ScalaJson
2.4.1 Scala/Java
Json Smart
https://github.com/netplex/json-smart-
v2
2.1.0 Java
Argonaut http://argonaut.io/ 6.0.4 Scala
JAWN https://github.com/non/jawn 0.8.0 Scala
4
47deg.com
THE PARSERS (1 OF 4)
• Scala Library. This parser is part of the standard Scala
library in package scala.util.parsing.json. It is
implemented using parsing combinators.
• Twitter Json. A cleaned up version of the JSON parser in
Odersky's Scala book. It is implemented using parsing
combinators. Written by Steve Jenson while at Twitter.
• Persist Json. Developed as part of the OStore, a new
NoSQL database written in Scala. OStore started with the
Twitter parser. This turned out to be much too slow, so it
was rewritten from scratch keeping mostly the same API but
with an emphasis on speed. Developed by John Nestor
(with the codex based mapper by JR Dejardin).
5
47deg.com
THE PARSERS (2 OF 4)
• Play Json. A part of the Typesafe Play framework.
Implemented using Jerkson, a Scala wrapper on
Jackson.
• Lift Json. Developed as part of Lift, a framework for
building web apps.
• Spray Json. Developed as part of Spray, a REST/
HTTP network IO toolkit.
6
47deg.com
THE PARSERS (3 OF 4)
• Argonaut. Purely functional Json in Scala. Uses
Scalaz.
• Rojama. Another Scala parser that makes extensive
use of Scala’s functional features. Developed by Robert
Macomber of Socrata.
• Jawn. Jawn was designed to parse JSON into an AST
as quickly as possible.
7
47deg.com
THE PARSERS (4 OF 4)
• Jackson. Generally regarded as the best and
fastest Java Json parser. Has a very rich set of
features. We test using the DefaultScalaModule
(by Chris Currie) that provides Scala support.
• Json Smart. A newer faster (than Jackson) Json
parser written in Java.
8
47deg.com
TEST SETS FOR PERFORMANCE TESTING
• Twitter. Tweets processed by the Yap.tv Guide 

(http://j.mp/15WL0p3), a service providing a personalized TV
guide companion experience based on social content from
Twitter and Facebook.This data set contains 100 tweets in Json 

(http://j.mp/13lKbU6).
• Google. PlaceSearchResults returned by Google in response
to place queries at 100 locations. The locations correspond to
the top best places to live in 2012, as compiled by CNN Money
(http://j.mp/13NmVid). This data set contains 138
PlaceSearchResults in Json (http://j.mp/13NmCUC) using
keyword “brewery” and a radius of 2 miles.
• Each file has one Json object per line.
9
47deg.com
PRETTY SAMPLE TWITTER JSON
{"contributors":null,
"coordinates":null,
"created_at":"Mon Jun 27 21:45:46 +0000 2011",
"entities":
{"hashtags":[],
"urls":
[{"display_url":"mercynotes.com",
"expanded_url":"http://www.mercynotes.com/",
"indices":[61,80],
"url":"http://t.co/lKzLFOd"
}
],
"user_mentions":[]
},
"favorited":false,
"geo":null,
"id":85463859615379456,
"id_str":"85463859615379456",
"in_reply_to_screen_name":null,
"in_reply_to_status_id":null,
"in_reply_to_status_id_str":null,
"in_reply_to_user_id":null,
"in_reply_to_user_id_str":null,
"place":null,
"retweet_count":0,
"retweeted":false,
"source":"web",
"text":
"Been watching Wimbledon? Check out new post Love and Tennis: http://t.co/lKzLFOd",
"truncated":false,
"user":
{"contributors_enabled":false,
"created_at":"Mon May 30 16:35:44 +0000 2011",
"default_profile":true,
"default_profile_image":false,
"description":"",
"favourites_count":0,
"follow_request_sent":null,
"followers_count":6,
"following":null,
"friends_count":12,
"geo_enabled":false,
"id":307978890,
"id_str":"307978890",
"is_translator":false,
"lang":"en",
"listed_count":0,
"location":"NC",
"name":"Julie LaJoe",
"notifications":null,
"profile_background_color":"C0DEED",
"profile_background_image_url":
"http://a0.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https":
"https://si0.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile":false,
"profile_image_url":
"http://a0.twimg.com/profile_images/1375001769/JulieMNnew__2__normal.jpg",
"profile_image_url_https":
"https://si0.twimg.com/profile_images/1375001769/JulieMNnew__2__normal.jpg",
"profile_link_color":"0084B4",
"profile_sidebar_border_color":"C0DEED",
"profile_sidebar_fill_color":"DDEEF6",
"profile_text_color":"333333",
"profile_use_background_image":true,
"protected":false,
"screen_name":"mercynotes",
"show_all_inline_media":false,
"statuses_count":13,
"time_zone":"Quito",
"url":"http://mercynotes.com",
"utc_offset":-18000,
"verified":false
}
}
10
47deg.com
PRETTY SAMPLE GOOGLE JSON{"address_components":
[{"long_name":"622",
"short_name":"622",
"types":["street_number"]
},
{"long_name":"South Rangeline Road",
"short_name":"South Rangeline Road",
"types":["route"]
},
{"long_name":"Carmel",
"short_name":"Carmel",
"types":["locality","political"]
},
{"long_name":"Hamilton",
"short_name":"Hamilton",
"types":
["administrative_area_level_2","political"]
},
{"long_name":"Indiana",
"short_name":"Indiana",
"types":
["administrative_area_level_1","political"]
},
{"long_name":"US",
"short_name":"US",
"types":["country","political"]
},
{"long_name":"46032",
"short_name":"46032",
"types":["postal_code"]
}
],
"formatted_address":
"Suite Q, 622 South Rangeline Road, Carmel, Indiana, United States",
"formatted_phone_number":"(317) 429-6345",
"geometry":
{"location":{"lat":39.971703,"lng":-86.129099}},
"icon":
"http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id":"fcd83d32717980ec1fec2c7ec8719389b201a331",
"international_phone_number":"+1 317-429-6345",
"name":"Union Brewing Company",
"opening_hours":
{"open_now":true,
"periods":
[{"close":{"day":0,"time":"2000"},
"open":{"day":0,"time":"1200"}
},
{"close":{"day":2,"time":"2200"},
"open":{"day":2,"time":"1600"}
},
{"close":{"day":4,"time":"2200"},
"open":{"day":4,"time":"1600"}
},
{"close":{"day":6,"time":"0000"},
"open":{"day":5,"time":"1500"}
},
{"close":{"day":0,"time":"0000"},
"open":{"day":6,"time":"1200"}
}
]
},
"photos":
[{"height":1632,
"html_attributions":
["<a href="https://plus.google.com/117934275405882297051">Greg Magnusson</a>"
],
"photo_reference":
"CnRoAAAAvN9y_gkgZIGa13kUSyyBlqwholvjtH4NKo-BzvlklcX-Tt9Ysc6HRMXPxKl3PumZtiOnomHi-Nk83y-lxf8RX8nsWulwuCBpY2okAqaU9wohOhncStFPZlKr02t3WquA6pt8mfCYYO-
NAdU2HwdM1hIQYJmus4wpQBaRtP7BFdYhzRoU4XvzfAAQQwkdJZluFJ-tDoUulIo",
"width":1224
}
],
"reference":
"CoQBcgAAAF3VKrWBUmLMv5tLs1Ru47j3Tbxa6lPxlIFj5BUvpsTyPt3bpui2vOTCcaHjKYuAjSulIPHpd0YFgm5CKLQH6P_19xU1UPeu6avWeIMWA0u4hxyx4TazCfFF9ESCwHaOEcKZfRyJSD2b5p2IJvT0eVkFFExeWbqAcWrH80jIQ-
VrEhAvUSpbmH3rB4LEKn-cZtsYGhQxFpeco4U1rUtwe-ncAttqLBnSgQ",
"reviews":
[{"aspects":[{"rating":3,"type":"quality"}],
"author_name":"Greg Magnusson",
"author_url":
"https://plus.google.com/117934275405882297051",
"text":
"Truly outstanding local craft brewing company. Indy&#39;s got some great local brewers, but these guys really get it right. Nice little location in Carmel, great beer and local guest taps...
I&#39;m so glad these guys moved into town. Love!",
"time":1361059887
}
],
"types":["food","establishment"],
"url":
"https://plus.google.com/102928473191458623183/about?hl=en-US",
"utc_offset":-300,
"vicinity":
"Suite Q, 622 South Rangeline Road, Carmel",
"website":"http://www.unionbrewingco.com"
}
11
47deg.com
• Timing is done with Java System.nanotime().
• For each data set, each line is processed.
• This is repeated 25 time to warm JVM.
• This is repeated 200 times for measurement.
• For example, google has 138 Json lines, so during
warmup a total of 3450 lines are parsed and during
testing 27600 lines are parsed.
• The total summed nanoseconds for all 27600 parse
steps are reported as milliseconds for each parser.
TESTING PROCESS
12
47deg.com
TIMING SCALA/JAVA CODE
• Timing is tricky! For example see
• http://www.ibm.com/developerworks/library/j-
benchmark1/
• A few of the many issues:
• Warmup (run several times to warm JVM)
• Repeatability (use average?, but what about P99?)
• Interference from other processes
• Caches
• Garbage collection
• Chosen data set
13
47deg.com
TESTING MACHINE
• Times obviously depend on speed of machine used in
testing.
• Numbers here are for a MacBook pro with
• 2 2.9 GHz cores
• 16GB of main memory
• You can run tests on a machine of your choice!
14
47deg.com
PARSING TIMES (MS)
Parser Twitter Google Ignore
Persist Json 443 712
Rojoma 540 1251
Jackson 445 842
Spray Json 603 1115
Lift Json 469 1002
Twitter Json 18179 42316 Too Slow
Scala Library 126006 329215 Way Too Slow
Play Json 442 1027
Json Smart 251 424
Argonaut 784 1448
JAWN 603 748
15
47deg.com
PARSING TIMES - TWITTER
16
47deg.com
PARSING TIMES - GOOGLE
17
47deg.com
WHY IS TWITTER SLOW?
• Parsing combinators.
Elegant but slow.
• Interpreted.
Backtracking.


18
def value: Parser[Any] = obj | arr | string | number |

"null" ^^ (x => null) | "true" ^^ (x => true) | "false"
^^ (x => false)



def obj: Parser[Map[String, Any]] = "{" ~> repsep(member,
",") <~ "}" ^^ (Map.empty ++ _)



def arr: Parser[List[Any]] = "[" ~> repsep(value, ",") <~
"]"



def member: Parser[(String, Any)] = string ~ ":" ~ value
^^ {

case name ~ ":" ~ value => (name, value)

}
47deg.com
WHY IS THE SCALA LIBRARY EVEN
SLOWER?
• Like Twitter uses parsing combinators.
• But why is it so much slower?
19
47deg.com
WHY IS PLAY SO SLOW IF IT USES
JACKSON?
• It uses Jerkson (which is abandoned)?
• ???
20
47deg.com
JSON LANGUAGE EXTENSIONS
Parser Comments NoQuotes Root Type Other
Persist Json // eld any raw strings
Rojoma //,/**/ eld any keeps eld order
Jackson // field object can use ‘
Spray Json // any
Lift Json object keeps eld order
Twitter Json any
Scala Library any
Play Json object
Json Smart # eld/value object
Argonaut object keeps eld order
JAWN object
21
47deg.com
PARSER RESULTS (ASTS)
Parser Object, Array
Wrapped in
Object
Immutable Collections
Persist Json Map, List no yes Scala
Rojoma LinkedHashMap, Vector yes no Scala
Jackson Map, List yes no Java
Spray Json Map, Vector yes yes Scala
Lift Json List[Field], List yes yes Scala
Twitter Json Map, List no yes Scala
Scala Library Map, List yes yes Scala
Play Json Map, List yes yes Scala
Json Smart HashMap, List yes no Java
Argonaut scalaz.InsertionMap, List yes yes Scala
JAWN Map, Array yes no Scala
22
47deg.com
UNPARSING
• The inverse of parsing (deserialization) is unparsing
(serialization).
• Unparsing takes the AST from parsing and converts it back to
a string.
• Useful for debugging and logging.
• Many parsers also include a pretty printed unparser.
• Timing here for the “non-pretty” simple form.
23
47deg.com
UN-PARSING TIMES (MS)
Parser Twitter Google
Persist Json 622 1172
Rojoma 226 511
Jackson 11 29
Spray Json 232 676
Lift Json 1125 3211
Play Json 322 323
Json Smart 349 934
Argonaut 1005 2468
JAWN 498 1161
24
47deg.com
UN-PARSING TIMES - TWITTER
25
47deg.com
UN-PARSING TIMES - GOOGLE
26
47deg.com
WHY IS JACKSON SO INCREDIBLY FAST?
• Uses SegmentedStringBuilder (rather than
StringBuilder).
• Uses segmented internal buffer.
• Buffers are recycled.
27
47deg.com
WHY IS PERSIST SLOW?
• Uses raw Seq and Map rather than being
wrapped in custom classes.
• Must use pattern match rather than virtual
dispatch to a virtual method.
28
47deg.com
MAPPERS
• Parsers go from string to AST
• Mappers go to user specified case classes
• Twitter, Scala Library, Json Smart, JAWN: no
mapper
• Jackson, Argonaut, Rojoma: 

string => case classes
• Others: string => AST => case classes
29
47deg.com
DYNAMIC VERSUS STATIC TYPING
• Dynamic: AST. More flexible and agile. No additional code
needed for parsing. Can be used on any valid json data. But
need extra code if more checking is needed.
• Static: User Specified Case Classes. Must specify case
classes before parsing can proceed. More checking. Can
attach behavior to case classes.
30
47deg.com
MAPPING TIMES (MS)
Parser Twitter Google
Persist Json 622 2238
Rojoma 1117 2669
Jackson 326 1150
Spray Json 557 1675
Lift Json 520 2060
Play Json 1123 3768
Argonaut 937 2550
31
47deg.com
MAPPING TIMES - TWITTER
32
47deg.com
MAPPING TIMES - GOOGLE
33
47deg.com
MAPPERS
Parser Extra Code Lines Why
Persist Json 0
Rojoma 135 case classes, Array=>Seq
Jackson 0
Spray Json 16 case classes
Lift Json 7 BigDecimal
Play Json 16 case classes
Argonaut 180
case classes, Array=>List,
Seq=>List, BigDecimal=>Double
34
47deg.com
AVOIDING EXTRA CODE
• Find types of case class parameter names. Java
reflection works.
• Find names of case class parameters. Prior to Java 8
not available via Java reflection. Scala reflection
however does work.
• Reflection can be quite slow. Caching can help!
• Persist: Shapeless
• Lift and Jackson: Paranamer. Gets info from reading
Java byte code symbol tables.
35
47deg.com
SUMMARY
• Avoid: Scala Library, Twitter
• Fast parse and no other features: Json Smart
• Good overall choices: Jackson, Persist, Spray
• Very fast unparse: Jackson
36
47deg.com
QUESTIONS
37
QUESTIONS
47deg.com
THANKS!
38
QUESTIONS
To contact me or 47 Degrees:
Email

nestor@persist.com
hello@47deg.com
Twitter

@47deg
Web

47deg.com

Mais conteĂşdo relacionado

Mais procurados

Mais procurados (14)

인피니스팬데이터그리드따라잡기 (@JCO 2014)
인피니스팬데이터그리드따라잡기 (@JCO 2014)인피니스팬데이터그리드따라잡기 (@JCO 2014)
인피니스팬데이터그리드따라잡기 (@JCO 2014)
 
Ehcache 3: JSR-107 on steroids at Devoxx Morocco
Ehcache 3: JSR-107 on steroids at Devoxx MoroccoEhcache 3: JSR-107 on steroids at Devoxx Morocco
Ehcache 3: JSR-107 on steroids at Devoxx Morocco
 
Java profiling Do It Yourself (jug.msk.ru 2016)
Java profiling Do It Yourself (jug.msk.ru 2016)Java profiling Do It Yourself (jug.msk.ru 2016)
Java profiling Do It Yourself (jug.msk.ru 2016)
 
Java black box profiling JUG.EKB 2016
Java black box profiling JUG.EKB 2016Java black box profiling JUG.EKB 2016
Java black box profiling JUG.EKB 2016
 
PostgreSQL: meet your queue
PostgreSQL: meet your queuePostgreSQL: meet your queue
PostgreSQL: meet your queue
 
Performance tests with Gatling
Performance tests with GatlingPerformance tests with Gatling
Performance tests with Gatling
 
Ehcache 3 @ BruJUG
Ehcache 3 @ BruJUGEhcache 3 @ BruJUG
Ehcache 3 @ BruJUG
 
[124] mit cheetah 로봇의 탄생
[124] mit cheetah 로봇의 탄생[124] mit cheetah 로봇의 탄생
[124] mit cheetah 로봇의 탄생
 
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
 
Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on G...
Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on G...Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on G...
Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on G...
 
High Performance Distributed TensorFlow with GPUs - TensorFlow Chicago Meetup...
High Performance Distributed TensorFlow with GPUs - TensorFlow Chicago Meetup...High Performance Distributed TensorFlow with GPUs - TensorFlow Chicago Meetup...
High Performance Distributed TensorFlow with GPUs - TensorFlow Chicago Meetup...
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akka
 
Event Driven Architectures with Camel
Event Driven Architectures with CamelEvent Driven Architectures with Camel
Event Driven Architectures with Camel
 
I know why your Java is slow
I know why your Java is slowI know why your Java is slow
I know why your Java is slow
 

Destaque

Testing, CI and CD in the real world
Testing, CI and CD in the real worldTesting, CI and CD in the real world
Testing, CI and CD in the real world
Roc Boronat
 
7. proyecto pedagĂłgico maruamake
7. proyecto pedagĂłgico maruamake7. proyecto pedagĂłgico maruamake
7. proyecto pedagĂłgico maruamake
CEISanJose
 
CapĂ­tulo 6 objetivos y estrategias
CapĂ­tulo 6 objetivos y estrategiasCapĂ­tulo 6 objetivos y estrategias
CapĂ­tulo 6 objetivos y estrategias
darkpipa
 
DirecciĂłn postal
DirecciĂłn postalDirecciĂłn postal
DirecciĂłn postal
jims1995
 

Destaque (20)

Introduction to JSON and Building Youtube, Twitter and Wikipedia Web Apps
Introduction to JSON and Building Youtube, Twitter and Wikipedia Web AppsIntroduction to JSON and Building Youtube, Twitter and Wikipedia Web Apps
Introduction to JSON and Building Youtube, Twitter and Wikipedia Web Apps
 
Json vs Gson vs Jackson
Json vs Gson vs JacksonJson vs Gson vs Jackson
Json vs Gson vs Jackson
 
Neural Network on Akka
Neural Network on AkkaNeural Network on Akka
Neural Network on Akka
 
Akka Streams and HTTP
Akka Streams and HTTPAkka Streams and HTTP
Akka Streams and HTTP
 
Composing Project Archetyps with SBT AutoPlugins
Composing Project Archetyps with SBT AutoPluginsComposing Project Archetyps with SBT AutoPlugins
Composing Project Archetyps with SBT AutoPlugins
 
Transformative Git Practices
Transformative Git PracticesTransformative Git Practices
Transformative Git Practices
 
Testing, CI and CD in the real world
Testing, CI and CD in the real worldTesting, CI and CD in the real world
Testing, CI and CD in the real world
 
Your code as a crime scene
Your code as a crime sceneYour code as a crime scene
Your code as a crime scene
 
Redescubre la programación - #MPWAR - #OpenDayLaSalle
Redescubre la programación - #MPWAR - #OpenDayLaSalleRedescubre la programación - #MPWAR - #OpenDayLaSalle
Redescubre la programación - #MPWAR - #OpenDayLaSalle
 
Golang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyGolang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war story
 
Becker
BeckerBecker
Becker
 
7. proyecto pedagĂłgico maruamake
7. proyecto pedagĂłgico maruamake7. proyecto pedagĂłgico maruamake
7. proyecto pedagĂłgico maruamake
 
Fairline Yacht Club magazine - Yacht Brokerage - September 2011 issue
Fairline Yacht Club magazine - Yacht Brokerage - September 2011 issueFairline Yacht Club magazine - Yacht Brokerage - September 2011 issue
Fairline Yacht Club magazine - Yacht Brokerage - September 2011 issue
 
Mundep070813
Mundep070813Mundep070813
Mundep070813
 
IL WEB DEL COMUNE report
IL WEB DEL COMUNE  reportIL WEB DEL COMUNE  report
IL WEB DEL COMUNE report
 
CapĂ­tulo 6 objetivos y estrategias
CapĂ­tulo 6 objetivos y estrategiasCapĂ­tulo 6 objetivos y estrategias
CapĂ­tulo 6 objetivos y estrategias
 
Open mapi agorum core - vortrag
Open mapi   agorum core - vortragOpen mapi   agorum core - vortrag
Open mapi agorum core - vortrag
 
leo15
leo15leo15
leo15
 
Haciendo negocios en MĂŠjico
Haciendo negocios en MĂŠjicoHaciendo negocios en MĂŠjico
Haciendo negocios en MĂŠjico
 
DirecciĂłn postal
DirecciĂłn postalDirecciĂłn postal
DirecciĂłn postal
 

Semelhante a Scala Json Features and Performance

Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011
Raymond Roestenburg
 
Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalache
Iasi code camp 12 october 2013   jax-rs-jee-ecosystem - catalin mihalacheIasi code camp 12 october 2013   jax-rs-jee-ecosystem - catalin mihalache
Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalache
Codecamp Romania
 

Semelhante a Scala Json Features and Performance (20)

JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Logstash
LogstashLogstash
Logstash
 
PostgreSQL is the new NoSQL - at Devoxx 2018
PostgreSQL is the new NoSQL  - at Devoxx 2018PostgreSQL is the new NoSQL  - at Devoxx 2018
PostgreSQL is the new NoSQL - at Devoxx 2018
 
Benchmarking Solr Performance at Scale
Benchmarking Solr Performance at ScaleBenchmarking Solr Performance at Scale
Benchmarking Solr Performance at Scale
 
Understanding DSE Search by Matt Stump
Understanding DSE Search by Matt StumpUnderstanding DSE Search by Matt Stump
Understanding DSE Search by Matt Stump
 
Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011
 
mjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profilingmjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profiling
 
On-boarding with JanusGraph Performance
On-boarding with JanusGraph PerformanceOn-boarding with JanusGraph Performance
On-boarding with JanusGraph Performance
 
Galaxy RNA-Seq Analysis: Tuxedo Protocol
Galaxy RNA-Seq Analysis: Tuxedo ProtocolGalaxy RNA-Seq Analysis: Tuxedo Protocol
Galaxy RNA-Seq Analysis: Tuxedo Protocol
 
Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalache
Iasi code camp 12 october 2013   jax-rs-jee-ecosystem - catalin mihalacheIasi code camp 12 october 2013   jax-rs-jee-ecosystem - catalin mihalache
Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalache
 
Tales from the four-comma club: Managing Kafka as a service at Salesforce | L...
Tales from the four-comma club: Managing Kafka as a service at Salesforce | L...Tales from the four-comma club: Managing Kafka as a service at Salesforce | L...
Tales from the four-comma club: Managing Kafka as a service at Salesforce | L...
 
The Pushdown of Everything by Stephan Kessler and Santiago Mola
The Pushdown of Everything by Stephan Kessler and Santiago MolaThe Pushdown of Everything by Stephan Kessler and Santiago Mola
The Pushdown of Everything by Stephan Kessler and Santiago Mola
 
Building Enterprise Search Engines using Open Source Technologies
Building Enterprise Search Engines using Open Source TechnologiesBuilding Enterprise Search Engines using Open Source Technologies
Building Enterprise Search Engines using Open Source Technologies
 
Building Enterprise Search Engines using Open Source Technologies
Building Enterprise Search Engines using Open Source TechnologiesBuilding Enterprise Search Engines using Open Source Technologies
Building Enterprise Search Engines using Open Source Technologies
 
Introduction to Galaxy and RNA-Seq
Introduction to Galaxy and RNA-SeqIntroduction to Galaxy and RNA-Seq
Introduction to Galaxy and RNA-Seq
 
Typesafe spark- Zalando meetup
Typesafe spark- Zalando meetupTypesafe spark- Zalando meetup
Typesafe spark- Zalando meetup
 
De Java 8 a Java 11 y 14
De Java 8 a Java 11 y 14De Java 8 a Java 11 y 14
De Java 8 a Java 11 y 14
 
Migration strategies 4
Migration strategies 4Migration strategies 4
Migration strategies 4
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOne
 

Mais de John Nestor (8)

LambdaFlow: Scala Functional Message Processing
LambdaFlow: Scala Functional Message Processing LambdaFlow: Scala Functional Message Processing
LambdaFlow: Scala Functional Message Processing
 
LambdaTest
LambdaTestLambdaTest
LambdaTest
 
Type Checking Scala Spark Datasets: Dataset Transforms
Type Checking Scala Spark Datasets: Dataset TransformsType Checking Scala Spark Datasets: Dataset Transforms
Type Checking Scala Spark Datasets: Dataset Transforms
 
Logging in Scala
Logging in ScalaLogging in Scala
Logging in Scala
 
Messaging patterns
Messaging patternsMessaging patterns
Messaging patterns
 
Experience Converting from Ruby to Scala
Experience Converting from Ruby to ScalaExperience Converting from Ruby to Scala
Experience Converting from Ruby to Scala
 
Scala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big DataScala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big Data
 
Neutronium
NeutroniumNeutronium
Neutronium
 

Último

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Último (20)

%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 

Scala Json Features and Performance

  • 1. SCALA JSON FEATURES AND PERFORMANCES John Nestor- 47 Degrees nestor@persist.com Dragos Manolescu dam@micro-workflow.com https://github.com/47deg/json-perf 47deg.com 1
  • 2. 47deg.com DISCLAIMER • Best effort attempt to measure performance and describe features. • Corrections always appreciated. • Also let us know any Json parsers we missed. 47deg.com 2
  • 3. 47deg.com • There are lots of Scala Json parsers • You can also use Java Json parsers in Scala • How to Choose: • Performance • Features • API • Support (will not be abandoned) • License (most are Apache 2) SCALA JSON 3
  • 4. 47deg.com SCALA (2.11) JSON PARSERS Parser URL Version Language Persist Json https://github.com/nestorpersist/json 1.1.0 Scala Rojoma https://github.com/rjmac/rojoma-json 3.3.0 Scala Jackson http://wiki.fasterxml.com/ JacksonHome 2.5.3 Scala/Java Spray Json https://github.com/spray/spray-json 1.3.2 Scala Lift Json https://github.com/lift/lift/tree/master/ framework/lift-base/lift-json/ 2.6.2 Scala Twitter Json https://github.com/stevej/scala-json NA Scala Scala Library https://github.com/scala/scala-parser- combinators 1.0.4 Scala Play Json https://www.playframework.com/ documentation/2.0/ScalaJson 2.4.1 Scala/Java Json Smart https://github.com/netplex/json-smart- v2 2.1.0 Java Argonaut http://argonaut.io/ 6.0.4 Scala JAWN https://github.com/non/jawn 0.8.0 Scala 4
  • 5. 47deg.com THE PARSERS (1 OF 4) • Scala Library. This parser is part of the standard Scala library in package scala.util.parsing.json. It is implemented using parsing combinators. • Twitter Json. A cleaned up version of the JSON parser in Odersky's Scala book. It is implemented using parsing combinators. Written by Steve Jenson while at Twitter. • Persist Json. Developed as part of the OStore, a new NoSQL database written in Scala. OStore started with the Twitter parser. This turned out to be much too slow, so it was rewritten from scratch keeping mostly the same API but with an emphasis on speed. Developed by John Nestor (with the codex based mapper by JR Dejardin). 5
  • 6. 47deg.com THE PARSERS (2 OF 4) • Play Json. A part of the Typesafe Play framework. Implemented using Jerkson, a Scala wrapper on Jackson. • Lift Json. Developed as part of Lift, a framework for building web apps. • Spray Json. Developed as part of Spray, a REST/ HTTP network IO toolkit. 6
  • 7. 47deg.com THE PARSERS (3 OF 4) • Argonaut. Purely functional Json in Scala. Uses Scalaz. • Rojama. Another Scala parser that makes extensive use of Scala’s functional features. Developed by Robert Macomber of Socrata. • Jawn. Jawn was designed to parse JSON into an AST as quickly as possible. 7
  • 8. 47deg.com THE PARSERS (4 OF 4) • Jackson. Generally regarded as the best and fastest Java Json parser. Has a very rich set of features. We test using the DefaultScalaModule (by Chris Currie) that provides Scala support. • Json Smart. A newer faster (than Jackson) Json parser written in Java. 8
  • 9. 47deg.com TEST SETS FOR PERFORMANCE TESTING • Twitter. Tweets processed by the Yap.tv Guide 
 (http://j.mp/15WL0p3), a service providing a personalized TV guide companion experience based on social content from Twitter and Facebook.This data set contains 100 tweets in Json 
 (http://j.mp/13lKbU6). • Google. PlaceSearchResults returned by Google in response to place queries at 100 locations. The locations correspond to the top best places to live in 2012, as compiled by CNN Money (http://j.mp/13NmVid). This data set contains 138 PlaceSearchResults in Json (http://j.mp/13NmCUC) using keyword “brewery” and a radius of 2 miles. • Each le has one Json object per line. 9
  • 10. 47deg.com PRETTY SAMPLE TWITTER JSON {"contributors":null, "coordinates":null, "created_at":"Mon Jun 27 21:45:46 +0000 2011", "entities": {"hashtags":[], "urls": [{"display_url":"mercynotes.com", "expanded_url":"http://www.mercynotes.com/", "indices":[61,80], "url":"http://t.co/lKzLFOd" } ], "user_mentions":[] }, "favorited":false, "geo":null, "id":85463859615379456, "id_str":"85463859615379456", "in_reply_to_screen_name":null, "in_reply_to_status_id":null, "in_reply_to_status_id_str":null, "in_reply_to_user_id":null, "in_reply_to_user_id_str":null, "place":null, "retweet_count":0, "retweeted":false, "source":"web", "text": "Been watching Wimbledon? Check out new post Love and Tennis: http://t.co/lKzLFOd", "truncated":false, "user": {"contributors_enabled":false, "created_at":"Mon May 30 16:35:44 +0000 2011", "default_profile":true, "default_profile_image":false, "description":"", "favourites_count":0, "follow_request_sent":null, "followers_count":6, "following":null, "friends_count":12, "geo_enabled":false, "id":307978890, "id_str":"307978890", "is_translator":false, "lang":"en", "listed_count":0, "location":"NC", "name":"Julie LaJoe", "notifications":null, "profile_background_color":"C0DEED", "profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png", "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme1/bg.png", "profile_background_tile":false, "profile_image_url": "http://a0.twimg.com/profile_images/1375001769/JulieMNnew__2__normal.jpg", "profile_image_url_https": "https://si0.twimg.com/profile_images/1375001769/JulieMNnew__2__normal.jpg", "profile_link_color":"0084B4", "profile_sidebar_border_color":"C0DEED", "profile_sidebar_fill_color":"DDEEF6", "profile_text_color":"333333", "profile_use_background_image":true, "protected":false, "screen_name":"mercynotes", "show_all_inline_media":false, "statuses_count":13, "time_zone":"Quito", "url":"http://mercynotes.com", "utc_offset":-18000, "verified":false } } 10
  • 11. 47deg.com PRETTY SAMPLE GOOGLE JSON{"address_components": [{"long_name":"622", "short_name":"622", "types":["street_number"] }, {"long_name":"South Rangeline Road", "short_name":"South Rangeline Road", "types":["route"] }, {"long_name":"Carmel", "short_name":"Carmel", "types":["locality","political"] }, {"long_name":"Hamilton", "short_name":"Hamilton", "types": ["administrative_area_level_2","political"] }, {"long_name":"Indiana", "short_name":"Indiana", "types": ["administrative_area_level_1","political"] }, {"long_name":"US", "short_name":"US", "types":["country","political"] }, {"long_name":"46032", "short_name":"46032", "types":["postal_code"] } ], "formatted_address": "Suite Q, 622 South Rangeline Road, Carmel, Indiana, United States", "formatted_phone_number":"(317) 429-6345", "geometry": {"location":{"lat":39.971703,"lng":-86.129099}}, "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png", "id":"fcd83d32717980ec1fec2c7ec8719389b201a331", "international_phone_number":"+1 317-429-6345", "name":"Union Brewing Company", "opening_hours": {"open_now":true, "periods": [{"close":{"day":0,"time":"2000"}, "open":{"day":0,"time":"1200"} }, {"close":{"day":2,"time":"2200"}, "open":{"day":2,"time":"1600"} }, {"close":{"day":4,"time":"2200"}, "open":{"day":4,"time":"1600"} }, {"close":{"day":6,"time":"0000"}, "open":{"day":5,"time":"1500"} }, {"close":{"day":0,"time":"0000"}, "open":{"day":6,"time":"1200"} } ] }, "photos": [{"height":1632, "html_attributions": ["<a href="https://plus.google.com/117934275405882297051">Greg Magnusson</a>" ], "photo_reference": "CnRoAAAAvN9y_gkgZIGa13kUSyyBlqwholvjtH4NKo-BzvlklcX-Tt9Ysc6HRMXPxKl3PumZtiOnomHi-Nk83y-lxf8RX8nsWulwuCBpY2okAqaU9wohOhncStFPZlKr02t3WquA6pt8mfCYYO- NAdU2HwdM1hIQYJmus4wpQBaRtP7BFdYhzRoU4XvzfAAQQwkdJZluFJ-tDoUulIo", "width":1224 } ], "reference": "CoQBcgAAAF3VKrWBUmLMv5tLs1Ru47j3Tbxa6lPxlIFj5BUvpsTyPt3bpui2vOTCcaHjKYuAjSulIPHpd0YFgm5CKLQH6P_19xU1UPeu6avWeIMWA0u4hxyx4TazCfFF9ESCwHaOEcKZfRyJSD2b5p2IJvT0eVkFFExeWbqAcWrH80jIQ- VrEhAvUSpbmH3rB4LEKn-cZtsYGhQxFpeco4U1rUtwe-ncAttqLBnSgQ", "reviews": [{"aspects":[{"rating":3,"type":"quality"}], "author_name":"Greg Magnusson", "author_url": "https://plus.google.com/117934275405882297051", "text": "Truly outstanding local craft brewing company. Indy&#39;s got some great local brewers, but these guys really get it right. Nice little location in Carmel, great beer and local guest taps... I&#39;m so glad these guys moved into town. Love!", "time":1361059887 } ], "types":["food","establishment"], "url": "https://plus.google.com/102928473191458623183/about?hl=en-US", "utc_offset":-300, "vicinity": "Suite Q, 622 South Rangeline Road, Carmel", "website":"http://www.unionbrewingco.com" } 11
  • 12. 47deg.com • Timing is done with Java System.nanotime(). • For each data set, each line is processed. • This is repeated 25 time to warm JVM. • This is repeated 200 times for measurement. • For example, google has 138 Json lines, so during warmup a total of 3450 lines are parsed and during testing 27600 lines are parsed. • The total summed nanoseconds for all 27600 parse steps are reported as milliseconds for each parser. TESTING PROCESS 12
  • 13. 47deg.com TIMING SCALA/JAVA CODE • Timing is tricky! For example see • http://www.ibm.com/developerworks/library/j- benchmark1/ • A few of the many issues: • Warmup (run several times to warm JVM) • Repeatability (use average?, but what about P99?) • Interference from other processes • Caches • Garbage collection • Chosen data set 13
  • 14. 47deg.com TESTING MACHINE • Times obviously depend on speed of machine used in testing. • Numbers here are for a MacBook pro with • 2 2.9 GHz cores • 16GB of main memory • You can run tests on a machine of your choice! 14
  • 15. 47deg.com PARSING TIMES (MS) Parser Twitter Google Ignore Persist Json 443 712 Rojoma 540 1251 Jackson 445 842 Spray Json 603 1115 Lift Json 469 1002 Twitter Json 18179 42316 Too Slow Scala Library 126006 329215 Way Too Slow Play Json 442 1027 Json Smart 251 424 Argonaut 784 1448 JAWN 603 748 15
  • 18. 47deg.com WHY IS TWITTER SLOW? • Parsing combinators. Elegant but slow. • Interpreted. Backtracking. 
 18 def value: Parser[Any] = obj | arr | string | number |
 "null" ^^ (x => null) | "true" ^^ (x => true) | "false" ^^ (x => false)
 
 def obj: Parser[Map[String, Any]] = "{" ~> repsep(member, ",") <~ "}" ^^ (Map.empty ++ _)
 
 def arr: Parser[List[Any]] = "[" ~> repsep(value, ",") <~ "]"
 
 def member: Parser[(String, Any)] = string ~ ":" ~ value ^^ {
 case name ~ ":" ~ value => (name, value)
 }
  • 19. 47deg.com WHY IS THE SCALA LIBRARY EVEN SLOWER? • Like Twitter uses parsing combinators. • But why is it so much slower? 19
  • 20. 47deg.com WHY IS PLAY SO SLOW IF IT USES JACKSON? • It uses Jerkson (which is abandoned)? • ??? 20
  • 21. 47deg.com JSON LANGUAGE EXTENSIONS Parser Comments NoQuotes Root Type Other Persist Json // eld any raw strings Rojoma //,/**/ eld any keeps eld order Jackson // eld object can use ‘ Spray Json // any Lift Json object keeps eld order Twitter Json any Scala Library any Play Json object Json Smart # eld/value object Argonaut object keeps eld order JAWN object 21
  • 22. 47deg.com PARSER RESULTS (ASTS) Parser Object, Array Wrapped in Object Immutable Collections Persist Json Map, List no yes Scala Rojoma LinkedHashMap, Vector yes no Scala Jackson Map, List yes no Java Spray Json Map, Vector yes yes Scala Lift Json List[Field], List yes yes Scala Twitter Json Map, List no yes Scala Scala Library Map, List yes yes Scala Play Json Map, List yes yes Scala Json Smart HashMap, List yes no Java Argonaut scalaz.InsertionMap, List yes yes Scala JAWN Map, Array yes no Scala 22
  • 23. 47deg.com UNPARSING • The inverse of parsing (deserialization) is unparsing (serialization). • Unparsing takes the AST from parsing and converts it back to a string. • Useful for debugging and logging. • Many parsers also include a pretty printed unparser. • Timing here for the “non-pretty” simple form. 23
  • 24. 47deg.com UN-PARSING TIMES (MS) Parser Twitter Google Persist Json 622 1172 Rojoma 226 511 Jackson 11 29 Spray Json 232 676 Lift Json 1125 3211 Play Json 322 323 Json Smart 349 934 Argonaut 1005 2468 JAWN 498 1161 24
  • 27. 47deg.com WHY IS JACKSON SO INCREDIBLY FAST? • Uses SegmentedStringBuilder (rather than StringBuilder). • Uses segmented internal buffer. • Buffers are recycled. 27
  • 28. 47deg.com WHY IS PERSIST SLOW? • Uses raw Seq and Map rather than being wrapped in custom classes. • Must use pattern match rather than virtual dispatch to a virtual method. 28
  • 29. 47deg.com MAPPERS • Parsers go from string to AST • Mappers go to user specied case classes • Twitter, Scala Library, Json Smart, JAWN: no mapper • Jackson, Argonaut, Rojoma: 
 string => case classes • Others: string => AST => case classes 29
  • 30. 47deg.com DYNAMIC VERSUS STATIC TYPING • Dynamic: AST. More flexible and agile. No additional code needed for parsing. Can be used on any valid json data. But need extra code if more checking is needed. • Static: User Specied Case Classes. Must specify case classes before parsing can proceed. More checking. Can attach behavior to case classes. 30
  • 31. 47deg.com MAPPING TIMES (MS) Parser Twitter Google Persist Json 622 2238 Rojoma 1117 2669 Jackson 326 1150 Spray Json 557 1675 Lift Json 520 2060 Play Json 1123 3768 Argonaut 937 2550 31
  • 34. 47deg.com MAPPERS Parser Extra Code Lines Why Persist Json 0 Rojoma 135 case classes, Array=>Seq Jackson 0 Spray Json 16 case classes Lift Json 7 BigDecimal Play Json 16 case classes Argonaut 180 case classes, Array=>List, Seq=>List, BigDecimal=>Double 34
  • 35. 47deg.com AVOIDING EXTRA CODE • Find types of case class parameter names. Java reflection works. • Find names of case class parameters. Prior to Java 8 not available via Java reflection. Scala reflection however does work. • Reflection can be quite slow. Caching can help! • Persist: Shapeless • Lift and Jackson: Paranamer. Gets info from reading Java byte code symbol tables. 35
  • 36. 47deg.com SUMMARY • Avoid: Scala Library, Twitter • Fast parse and no other features: Json Smart • Good overall choices: Jackson, Persist, Spray • Very fast unparse: Jackson 36
  • 38. 47deg.com THANKS! 38 QUESTIONS To contact me or 47 Degrees: Email
 nestor@persist.com hello@47deg.com Twitter
 @47deg Web
 47deg.com