Restructure zone getter to allow for lazy unpacking. #216
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Another alternative to #211 and #215.
This approach is much closer to the approach in #211, but cleans up a bunch of internals in the process.
We load data like below. This is the example at https://jsfiddle.net/rn58wmvn/3/.
The internal representation looks like this.
Now we try to load the data for
US/Central
.We check if there is an unpacked zone for
us_central
. There is not, so we continue.We then check if there is a packed string for
us_central
. There is not, so we continue.We then check if there is a link for
us_central
. There is a link,america_chicago
, so we callgetZone
onamerica_chicago
.We check if there is an unpacked zone for
america_chicago
. There is not, so we continue.We then check if there is a packed string for
america_chicago
. There is, so we unpack it. The data now looks like this.That zone is returned to the function looking for the
us_central
zone, and we use that and thenames
hash to populate the new zone. The data looks like this.Subsequent calls to get the zone for
America/Chicago
andUS/Central
will now be short-circuted by the check for an unpacked zone.The perf for this approach is roughly the same for the approach in #211.
This approach. http://jsperf.com/moment-timezone-unpack-on-demand/5
#211 approach. http://jsperf.com/moment-timezone-unpack-on-demand-2/2
I've only tested on a couple desktop browsers, so it would be good to see if the same perf improvements seen on android with @davidpean's implementation are applied here as well. cc @paulirish