forked from gobuffalo/plush
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbudget_config.go
More file actions
58 lines (48 loc) · 1.58 KB
/
Copy pathbudget_config.go
File metadata and controls
58 lines (48 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package plush
// BudgetCosts defines the work-unit cost for each operation type.
type BudgetCosts struct {
// LoopIteration is spent once per for-loop iteration.
// Default: 1
LoopIteration int64
// HelperCall is spent each time a registered helper is invoked.
// Default: 5
HelperCall int64
// FilterCall is spent per filter applied (sort, map, where).
// Default: 3
FilterCall int64
// SubRender is spent each time a partial/snippet is rendered.
// Default: 10
SubRender int64
// ConditionCheck is spent per if/unless/case evaluation.
// Default: 1
ConditionCheck int64
// Assignment is spent per variable assignment.
// Default: 0 (free — rarely the bottleneck)
Assignment int64
// ObjectTraversal is spent per dot-notation segment accessed.
// e.g. product.variants.first = 3 segments = 3 units
// Default: 1
ObjectTraversal int64
// FunctionCosts overrides the default HelperCall cost for specific named
// functions. The key is the function name as registered in the context.
// If a name is present here, its cost is used instead of HelperCall.
// e.g. costs.FunctionCosts = map[string]int64{"expensiveQuery": 50}
FunctionCosts map[string]int64
}
// DefaultBudgetCosts returns recommended production defaults.
func DefaultBudgetCosts() BudgetCosts {
return BudgetCosts{
LoopIteration: 1,
HelperCall: 5,
FilterCall: 3,
SubRender: 10,
ConditionCheck: 1,
Assignment: 0,
ObjectTraversal: 1,
}
}
// ZeroCosts returns all-zero costs.
// Useful for isolating one operation type in tests.
func ZeroCosts() BudgetCosts {
return BudgetCosts{}
}