git.delta.rocks / jrsonnet / refs/commits / f5b072424acc

difftreelog

perf(evaluator) remove inline attribute

Лач2020-06-25parent: #1a55b09.patch.diff
in: master

6 files changed

modifiedcrates/jsonnet-evaluator/Cargo.tomldiffbeforeafterboth
10default = ["serialized-stdlib", "faster"]10default = ["serialized-stdlib", "faster"]
11serialized-stdlib = ["serde", "bincode"]11serialized-stdlib = ["serde", "bincode"]
12# Replace some standard library functions with faster implementations12# Replace some standard library functions with faster implementations
13# Library works fine without this feature, but requires more memory and time for std function calls
13faster = []14faster = []
1415
15[dependencies]16[dependencies]
modifiedcrates/jsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
168future_wrapper!(HashMap<String, LazyBinding>, FutureNewBindings);168future_wrapper!(HashMap<String, LazyBinding>, FutureNewBindings);
169future_wrapper!(ObjValue, FutureObjValue);169future_wrapper!(ObjValue, FutureObjValue);
170170
171#[inline(always)]
172pub fn evaluate_comp<T>(171pub fn evaluate_comp<T>(
173 context: Context,172 context: Context,
174 value: &impl Fn(Context) -> Result<T>,173 value: &impl Fn(Context) -> Result<T>,
370 })369 })
371}370}
372371
373#[inline(always)]
374pub fn evaluate(context: Context, expr: &LocExpr) -> Result<Val> {372pub fn evaluate(context: Context, expr: &LocExpr) -> Result<Val> {
375 use Expr::*;373 use Expr::*;
376 let locexpr = expr.clone();374 let locexpr = expr.clone();
731 (ns, name) => panic!("Intristic not found: {}.{}", ns, name),729 (ns, name) => panic!("Intristic not found: {}.{}", ns, name),
732 },730 },
733 Val::Func(f) => {731 Val::Func(f) => {
734 let body = #[inline(always)]732 let body = || f.evaluate(context, args, *tailstrict);
735 || f.evaluate(context, args, *tailstrict);
736 if *tailstrict {733 if *tailstrict {
737 body()?734 body()?
modifiedcrates/jsonnet-evaluator/src/function.rsdiffbeforeafterboth
24///24///
25/// ## Notes25/// ## Notes
26/// This function is always inlined for tailstrict26/// This function is always inlined for tailstrict
27#[inline(always)]
28pub(crate) fn inline_parse_function_call(27pub(crate) fn inline_parse_function_call(
29 ctx: Context,28 ctx: Context,
30 body_ctx: Option<Context>,29 body_ctx: Option<Context>,
79 Ok(body_ctx.unwrap_or(ctx).extend(out, None, None, None)?)78 Ok(body_ctx.unwrap_or(ctx).extend(out, None, None, None)?)
80}79}
8180
82#[inline(always)]
83pub(crate) fn place_args(81pub(crate) fn place_args(
84 ctx: Context,82 ctx: Context,
85 body_ctx: Option<Context>,83 body_ctx: Option<Context>,
modifiedcrates/jsonnet-evaluator/src/lib.rsdiffbeforeafterboth
2#![feature(type_alias_impl_trait)]2#![feature(type_alias_impl_trait)]
3#![feature(debug_non_exhaustive)]3#![feature(debug_non_exhaustive)]
4#![allow(macro_expanded_macro_exports_accessed_by_absolute_paths)]4#![allow(macro_expanded_macro_exports_accessed_by_absolute_paths)]
5#![feature(stmt_expr_attributes)]
6mod ctx;5mod ctx;
7mod dynamic;6mod dynamic;
8mod error;7mod error;
81 /// Global state is fine there80 /// Global state is fine there
82 pub(crate) static EVAL_STATE: RefCell<Option<EvaluationState>> = RefCell::new(None)81 pub(crate) static EVAL_STATE: RefCell<Option<EvaluationState>> = RefCell::new(None)
83}82}
84#[inline(always)]
85pub(crate) fn with_state<T>(f: impl FnOnce(&EvaluationState) -> T) -> T {83pub(crate) fn with_state<T>(f: impl FnOnce(&EvaluationState) -> T) -> T {
86 EVAL_STATE.with(84 EVAL_STATE.with(
87 #[inline(always)]
88 |s| f(s.borrow().as_ref().unwrap()),85 |s| f(s.borrow().as_ref().unwrap()),
89 )86 )
90}87}
91pub(crate) fn create_error<T>(err: Error) -> Result<T> {88pub(crate) fn create_error<T>(err: Error) -> Result<T> {
92 with_state(|s| s.error(err))89 with_state(|s| s.error(err))
93}90}
94#[inline(always)]
95pub(crate) fn push<T>(e: LocExpr, comment: String, f: impl FnOnce() -> Result<T>) -> Result<T> {91pub(crate) fn push<T>(e: LocExpr, comment: String, f: impl FnOnce() -> Result<T>) -> Result<T> {
96 with_state(|s| s.push(e, comment, f))92 with_state(|s| s.push(e, comment, f))
97}93}
251 Context::new().extend_unbound(new_bindings, None, None, None)247 Context::new().extend_unbound(new_bindings, None, None, None)
252 }248 }
253249
254 #[inline(always)]
255 pub fn push<T>(&self, e: LocExpr, comment: String, f: impl FnOnce() -> Result<T>) -> Result<T> {250 pub fn push<T>(&self, e: LocExpr, comment: String, f: impl FnOnce() -> Result<T>) -> Result<T> {
256 {251 {
257 let mut stack = self.0.stack.borrow_mut();252 let mut stack = self.0.stack.borrow_mut();
287 Err(LocError(err, self.stack_trace()))282 Err(LocError(err, self.stack_trace()))
288 }283 }
289284
290 #[inline(always)]
291 fn run_in_state<T>(&self, f: impl FnOnce() -> T) -> T {285 fn run_in_state<T>(&self, f: impl FnOnce() -> T) -> T {
292 EVAL_STATE.with(|v| {286 EVAL_STATE.with(|v| {
293 let has_state = v.borrow().is_some();287 let has_state = v.borrow().is_some();
modifiedcrates/jsonnet-evaluator/src/map.rsdiffbeforeafterboth
18 }))18 }))
19 }19 }
2020
21 #[inline(always)]
22 pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V>21 pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V>
23 where22 where
24 K: Borrow<Q>,23 K: Borrow<Q>,
modifiedcrates/jsonnet-evaluator/src/val.rsdiffbeforeafterboth
77}77}
78impl FuncDesc {78impl FuncDesc {
79 /// This function is always inlined to make tailstrict work79 /// This function is always inlined to make tailstrict work
80 #[inline(always)]
81 pub fn evaluate(&self, call_ctx: Context, args: &ArgsDesc, tailstrict: bool) -> Result<Val> {80 pub fn evaluate(&self, call_ctx: Context, args: &ArgsDesc, tailstrict: bool) -> Result<Val> {
82 let ctx = inline_parse_function_call(81 let ctx = inline_parse_function_call(
83 call_ctx,82 call_ctx,
89 evaluate(ctx, &self.body)88 evaluate(ctx, &self.body)
90 }89 }
9190
92 #[inline(always)]
93 pub fn evaluate_values(&self, call_ctx: Context, args: &[Val]) -> Result<Val> {91 pub fn evaluate_values(&self, call_ctx: Context, args: &[Val]) -> Result<Val> {
94 let ctx = place_args(call_ctx, Some(self.ctx.clone()), &self.params, args)?;92 let ctx = place_args(call_ctx, Some(self.ctx.clone()), &self.params, args)?;
95 evaluate(ctx, &self.body)93 evaluate(ctx, &self.body)