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

Performance enhancement reducing clone #321

Closed
wants to merge 25 commits into from
Closed

Performance enhancement reducing clone #321

wants to merge 25 commits into from

Conversation

patefacio
Copy link
Contributor

No description provided.

- Renderer::render to not clone client provided Value
- Added RefOrOwned to treat references and cloned data the same
- Added CallStack which contains read-only borrow of user supplied context
- Added StackFrame for macro calls and for loops
- Added MacroCollection collect parsed `MacroDefinition`s by template
- `test_json_pointer`
- `test_simple_for_loop`
- `test_simple_nested_for_loop`
- `test_simple_assignment`
- `test_nested_for_var_access`
- `test_error_render_field_unknown_in_forloop` to match error message
- Fixed copy/paste error: `current_key` now returns key, not value
- Added `CallStack::error_location`
- Added `StackFrame::template_location`
- Split `find_value` into `find_value_(in_frame_context|in_for_loop)`
- Added back `set_global` support
- Cleaned `render_node` call `chain_err`
- Updated `test_error_in_macro_location` error expectation
- Updated `test_error_macros_self_inexisting` error expectation
- `add_set_values_in_context` working
- Makes `render_for` test pass
- Added back `do_super`
- Added `template` and `template_root` to AstProcessor
- Added `MAGICAL_DUMP_VAR` support
- Added Include FrameType and `push_include_frame`
- Fixed lifetimes on `find_value_...` functions
- Added `Accessor` impl for `CallStack`
- Update `AstProcessor` to use process_path for var processing
- Back to original benches, with one fix to `huge_loop`
- Removed `square_brackets`, covered by `path_processor`
- Fixed `eval_macro_call` to lookup macro in macro collection
- Renamed `from_template_root` -> `from_template_original`
- Removed unnecessary map creation of macro definition map
- Added `macto_namespace` to StrackFrame for macro lookup
- Clippy suggestions
- Used original `get_error_location`
- Added tests for path processing
Copy link
Owner

@Keats Keats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty huge diff, it's going to take me a while to review properly!

Left a couple of comments, the code could also use a rebase since there would be merge conflicts.

Cargo.toml Outdated
@@ -29,7 +29,10 @@ url = "1"
humansize = "1"
# used in date format filter
chrono = "0.4"
# used in instrument timing
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the 3 dependencies below should be in dev-dependencies then?

@@ -0,0 +1,104 @@
extern crate tera;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this file needed? can it be in bench instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed file.

@@ -0,0 +1,1064 @@
//! Responsible for walking ast and render implementation

// --- module use statements ---
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove all those comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

// assert_eq!(
// result.unwrap_err().iter().nth(1).unwrap().description(),
// "Variable arr[a] can not be evaluated because: Variable `a` not found in context while rendering \'tpl\'"
// );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be uncommented no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced this with a test.

Cargo.toml Outdated
@@ -29,7 +29,10 @@ url = "1"
humansize = "1"
# used in date format filter
chrono = "0.4"
# used in instrument timing
stopwatch = "^0.0.7"
log = "^0.3.8"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was logging used only when debugging? can it be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed stopwatch dependency. I do use log! by creating a macro called out! that points to log! for dev but can switch to println! if desire is to see logs from testing, since testing does not support.

I can remove this logging if you'd like, but maybe best to leave until you have time to review, in case need to review code more generally and logging might help. Whichever you prefer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I effectively did a rebase. My first and my first pull request, so I may have screwed it up. I hope it helps you diff more easily - but I'm not seeing how it helps so maybe I missed a step.

- Renderer::render to not clone client provided Value
- Added RefOrOwned to treat references and cloned data the same
- Added CallStack which contains read-only borrow of user supplied context
- Added StackFrame for macro calls and for loops
- Added MacroCollection collect parsed `MacroDefinition`s by template

Added more success test cases

- `test_json_pointer`
- `test_simple_for_loop`
- `test_simple_nested_for_loop`
- `test_simple_assignment`
- `test_nested_for_var_access`
- `test_error_render_field_unknown_in_forloop` to match error message

Added `test_simple_key_val_for_loop`

- Fixed copy/paste error: `current_key` now returns key, not value

Added `test_nested_key_val_for_loop`

Added back include impl, error_location

- Added `CallStack::error_location`
- Added `StackFrame::template_location`
- Split `find_value` into `find_value_(in_frame_context|in_for_loop)`
- Added back `set_global` support
- Cleaned `render_node` call `chain_err`

Added back renderer tests

- Updated `test_error_in_macro_location` error expectation
- Updated `test_error_macros_self_inexisting` error expectation

Patch `test_error_in_parent_template_location` expectations

For literal array - store value in Array, not RefOrOwned

- `add_set_values_in_context` working

Added `should_break_for_loop`

- Makes `render_for` test pass

Added `out` macro to toggle `info` vs `println`

- Added back `do_super`
- Added `template` and `template_root` to AstProcessor
- Added `MAGICAL_DUMP_VAR` support
- Added Include FrameType and `push_include_frame`

Extend lifetime of `context_value`

Added two big context benchmarks

Fix unused warning in `ref_or_owned`

Add `find_value_by_path`

Added `path_processor`

- Fixed lifetimes on `find_value_...` functions
- Added `Accessor` impl for `CallStack`
- Update `AstProcessor` to use process_path for var processing
- Back to original benches, with one fix to `huge_loop`
- Removed `square_brackets`, covered by `path_processor`

Fixed `MacroCollection` to track namespace->file

- Fixed `eval_macro_call` to lookup macro in macro collection
- Renamed `from_template_root` -> `from_template_original`

Relaxed some error tests

- Removed unnecessary map creation of macro definition map
- Added `macto_namespace` to StrackFrame for macro lookup
- Clippy suggestions
- Used original `get_error_location`
- Added tests for path processing

Added `bench_macro_big_object_no_loop_{set|macro_call}`

Fix remaining tests, relaxing text compare on failure

Added big no loop samples.
- Removed references to stopwatch
- Added missing assert in `error_unknown_index_variable`
Copy link
Owner

@Keats Keats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do the rebase myself but it's harder than just rebasing since string concat has been added to tera and this code need to handle it.

I don't think i will have the time this weekend or next week but I should be able to review it the week after (hopefully).

use context::get_json_pointer;
use serde_json::value::Value;

// --- module struct definitions ---
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I meant to remove these comments in every files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, removed those.

Keats pushed a commit that referenced this pull request Sep 1, 2018
This is ported from @patefacio PR: #321

All credits go to him
@Keats
Copy link
Owner

Keats commented Sep 1, 2018

Since the diff was so big, I ended up rewriting this PR to make sure I understood it well enough to maintain the codebase properly: the result is in #327

A few comments:

  • RefOrOwned exists in the std as Cow
  • it uncovered a few bugs with macros that I fixed but still need some digging/additional tests
  • the new structure is WAY cleaner than the old one: much easier to understand where we are not to mention allocating way less

I need to check if there are other places I can avoid allocating but overall thanks a lot for that PR, I marked you as author of #327 as it is mostly your work after all.

@Keats Keats closed this Sep 1, 2018
@patefacio
Copy link
Contributor Author

patefacio commented Sep 2, 2018 via email

@Keats
Copy link
Owner

Keats commented Sep 2, 2018

Someone recommended COW when I described the use-case and when I read its docs it sounded very different than my needs.

I do think it is the same overall, the main difference is that you can't add your own methods to it but it's not a big deal.

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.

2 participants