Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SBJson 4: Don't make me wait!
Search
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
生成AIを利用するだけでなく、投資できる組織へ
pospome
0
240
TypeScript 5.9 で使えるようになった import defer でパフォーマンス最適化を実現する
bicstone
1
1.2k
C-Shared Buildで突破するAI Agent バックテストの壁
po3rin
0
380
まだ間に合う!Claude Code元年をふりかえる
nogu66
2
330
【Streamlit x Snowflake】データ基盤からアプリ開発・AI活用まで、すべてをSnowflake内で実現
ayumu_yamaguchi
1
120
社内オペレーション改善のためのTypeScript / TSKaigi Hokuriku 2025
dachi023
1
560
Why Kotlin? 電子カルテを Kotlin で開発する理由 / Why Kotlin? at Henry
agatan
2
6.9k
チームをチームにするEM
hitode909
0
290
Microservices Platforms: When Team Topologies Meets Microservices Patterns
cer
PRO
1
1k
なあ兄弟、 余白の意味を考えてから UI実装してくれ!
ktcryomm
11
11k
從冷知識到漏洞,你不懂的 Web,駭客懂 - Huli @ WebConf Taiwan 2025
aszx87410
1
430
React Native New Architecture 移行実践報告
taminif
1
150
Featured
See All Featured
Writing Fast Ruby
sferik
630
62k
We Have a Design System, Now What?
morganepeng
54
7.9k
Optimising Largest Contentful Paint
csswizardry
37
3.5k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.3k
Facilitating Awesome Meetings
lara
57
6.7k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
Faster Mobile Websites
deanohume
310
31k
RailsConf 2023
tenderlove
30
1.3k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
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/