Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SBJson 4: Don't make me wait!
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Stig Brautaset
March 05, 2014
Programming
0
410
SBJson 4: Don't make me wait!
How SBJson 4 can help you get happy users.
Stig Brautaset
March 05, 2014
Tweet
Share
More Decks by Stig Brautaset
See All by Stig Brautaset
Delighting your users with SBJson 4
stig
1
1.3k
Other Decks in Programming
See All in Programming
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
380
AIとペアプロして処理時間を97%削減した話 #pyconshizu
kashewnuts
1
190
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
200
DSPy入門 Pythonで実現する自動プロンプト最適化 〜人手によるプロンプト調整からの卒業〜
seaturt1e
1
490
Claude Code の Skill で複雑な既存仕様をすっきり整理しよう
yuichirokato
1
270
Premier Disciplin for Micro Frontends Multi Version/ Framework Scenarios @OOP 2026, Munic
manfredsteyer
PRO
0
200
Rで始めるML・LLM活用入門
wakamatsu_takumu
0
150
浮動小数の比較について
kishikawakatsumi
0
370
Swift ConcurrencyでよりSwiftyに
yuukiw00w
0
240
TipKitTips
ktcryomm
0
150
あなたはユーザーではない #PdENight
kajitack
4
300
Geminiの機能を調べ尽くしてみた
naruyoshimi
0
190
Featured
See All Featured
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
63
Information Architects: The Missing Link in Design Systems
soysaucechin
0
810
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
330
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Agile that works and the tools we love
rasmusluckow
331
21k
The Cost Of JavaScript in 2023
addyosmani
55
9.7k
Automating Front-end Workflow
addyosmani
1370
200k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
93
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
950
Java REST API Framework Comparison - PWX 2021
mraible
34
9.2k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
140
Transcript
SBJson 4: Don’t make me wait! Stig Brautaset ~ @stigbra
Who am I? Started SBJson in 2007. Compulsively tinkered with
it since.
Fun facts 7 years on • 1012 commits • 4
major releases • 30 contributors • 3247 “stars” • 688 “forks”
–Every non-trivial app, ever. “Download a list of records &
display them to the user.”
What’s more important to your users? • Time until they
see the last record? • Or until they see the first?
The trouble with pagination • Repeated connection overhead • Records
fall in the cracks between pages • Records appear on two consecutive pages
Download-then-parse Time to first record Time to last record
Chunked delivery Time to first record Time to last record
Multi-core chunked delivery Time to first record Time to last
record
Relative time to first record 0 1.25 2.5 3.75 5
1 record 2 records 3 records 4 records 5 records Chunked delivery Traditional
NSJSONSerialisation • Supports NSStream! • But can’t do chunked delivery.
• We can do better!
SBJson 3 • Chunked delivery since June 2011 :-) •
But it was confusing and cumbersome to use… :-/ • …requiring multiple delegates chained together :-(
SBJson 4 • Drops category & OO interfaces • Focus
on chunked delivery • Introduces a block-based interface • Built specifically for two primary use cases
Multi-root JSON [1,2,3] {“foo”:42} [true,false]
Multi-root JSON id parser = [SBJson4Parser multiRootParserWithBlock:block errorHandler:eh];
Multi-root JSON [parser parse:data("[]{")]; // calls block(@[]) [parser parse:data("}[]"]; //
next part of stream // calls block(@{}) // calls block(@[])
Multi-root JSON [parser parse:data("[]{")]; // calls block(@[]) [parser parse:data("}[]"]; //
next part of stream // calls block(@{}) // calls block(@[])
Compromise: “garbage after JSON” []**xx block(@[]) errorHandler(…)
–Johnny Appleseed “What if I am using a 3rd-party API
that just gives me a long list?”
Root array chunks [ [1,2,3], {“foo”:42}, [true,false] ]
Unwrap the root array! id parser = [SBJson4Parser unwrapRootArrayParserWithBlock:block errorHandler:eh];
Unwrap the root array! [parser parse:data("[[],{")]; // calls block(@[]) [parser
parse:data("},true]")]; // calls block(@{}) // calls block(@(YES))
Unwrap the root array! [parser parse:data("[[],{")]; // calls block(@[]) [parser
parse:data("},true]")]; // calls block(@{}) // calls block(@(YES))
Compromise: Corrupted / incomplete JSON [ {}, [], ***###$#”>P block(@{})
block(@[]) errorHandler(…)
Unwrapping is for root-level arrays only!
SBJson’s Blocks SBJson4ValueBlock block = ^(id obj, BOOL *stop) {
if (some_condition) { *stop = YES; } else { // do something with obj } };
SBJson4ParserStatus switch ([parser parse:data]) { case SBJson4ParserStopped: case SBJson4ParserComplete: NSLog(“Done!");
case SBJson4ParserWaitingForData: break; case SBJson4ParserError: NSLog(@"Ouch, I'm hurt!"); break; }
Use with custom NSURLSessionDataDelegate - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dt didReceiveData:(NSData
*)data { switch ([parser parse: data]) { // handle various returns here… } }
Two CocoaPods! To allow both version 3 and 4 in
the same application.
http://www.flickr.com/photos/dullhunk/202872717/