Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-work Value to "final" API, cleaning up problems along the way #158

Merged
merged 10 commits into from
Jan 14, 2018

Conversation

epage
Copy link
Member

@epage epage commented Jan 14, 2018

This ended up causing significant performance improvement. It could have been more but for some reason the initial commit slowed down variables for some reason.

epage added 8 commits January 13, 2018 23:01
Template impact: There is now a consistent approach taken to when a
`Value` can be used as a string, whole number, fractional number, bool
etc.

Examples
- Every `Value` is now treated as a string.
- Whole numbers are now preserved.
- Whole numbers can convert to fractional numbers but not the other way
  around.
- You can convert a fractional number to a whole number using the
  filters `round`, `ceil`, or `floor`.
- Operations on only whole numbers preserve their whole number nature.
- for tag ranges, indexing, etc only accept whole numbers

Fixes cobalt-org#99

Programmatic impact:  This implements the `Value` refactor from cobalt-org#95.
`Value` is still an enum but now there is a single `Scalar` variant.
This scalar is not an enum but is convertible between each of the
common data types.  Optimizations are in place to natively store some of
these data types.

BREAKING CHANGE: `Value`'s API has changed. Conversion behavior within
templates has changed.
This was missed when adding support for `nil`.  `compact` removes `nil`s
from an array.  This does not implement the optional parameter to filter
out objects with a `nil` property.
This change attempts to strike a balance between what parts of the liquid API
need to be dynamic and static.  This makes the assumption that all block, tag,
and filter names are known statically and uses a `&'static str` to represent
them.

Old
```
running 6 tests
test bench_parse_template  ... bench:      24,715 ns/iter (+/- 1,966)
test bench_parse_text      ... bench:       2,610 ns/iter (+/- 248)
test bench_parse_variable  ... bench:       4,628 ns/iter (+/- 425)
test bench_render_template ... bench:       9,049 ns/iter (+/- 598)
test bench_render_text     ... bench:       2,204 ns/iter (+/- 151)
test bench_render_variable ... bench:       6,867 ns/iter (+/- 437)
```

New
```
running 6 tests
test bench_parse_template  ... bench:      22,625 ns/iter (+/- 1,986)
test bench_parse_text      ... bench:         826 ns/iter (+/- 58)
test bench_parse_variable  ... bench:       2,871 ns/iter (+/- 175)
test bench_render_template ... bench:       6,938 ns/iter (+/- 614)
test bench_render_text     ... bench:         432 ns/iter (+/- 29)
test bench_render_variable ... bench:       6,201 ns/iter (+/- 537)
```

In the long term, we want to stop cloning `LiquidOptions` on every parse and
`globals` on every render.  This change reduced the impact of the former.

BREAKING CHANGE: The API now takes `&'static str` instead of `String` for
block, tag, and filter names
epage added 2 commits January 13, 2018 23:36
`date` but not `date_in_tz` was updated to parse more than one date
format when cobalt switched formats.  This updates `date_in_tz` to do so
as well.

This was done by centralizing the date parsing logic as discussed in cobalt-org#48.
@epage epage merged commit 282c78d into cobalt-org:master Jan 14, 2018
@epage epage deleted the value branch January 14, 2018 07:04
@epage
Copy link
Member Author

epage commented Jan 15, 2018

My reference to fixing #99 is supposed to be #88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant