Writing a Fast JSON Parser
So, assuming all branches are correctly predicted (branch predictors operate in the frontend and don’t count towards dependency chains), let’s do a rough estimate of the cost of the loop above:
is the only instruction on the critical path – it carries a dependency across iterations of the loop. Thus, by using static branch prediction hints, the compiler can line up the instructions so the hot path flows in a straight line and all the cold paths are off somewhere else, sometimes saving register motion in the hot path. Converting sajson strings (e.g. ranges of UTF-8 memory) into Swift Strings is still expensive, but Swift 4 might improve the situation:
An iOS team at Dropbox replaced JSONSerialization with sajson and cut their initial load times by two thirds!
Source: chadaustin.me