Co-authored with
The following are the guidelines and strategies to keep in mind in order to design Metrics that will remain a maintainable size and compute as quickly as possible.
1. No Monolithic Metrics
A metric works best when it is doing one specific, well-defined job. If a metric is performing a large number of operations and transformations, it will inevitably grow large and slow. If there are multiple steps involved in the computation, we should break it down and extract each part into its own metric. This will enable the Pigment engine to optimize each piece separately and prevent any single metric from becoming huge and unusable. Having many light-weight, modular components is better than a single massive and unmaintainable monolith.
◻ Avoid doing too much in a single metric.
◻ Split complex logic into smaller, more narrowly targeted metrics.
2. Less is more: the fewer Dimensions, the better.
Less dimensions means less data involved in the computation, which avoids hitting cardinality limitations and makes the calculation complete faster. Make sure that a metric’s structure only includes the dimensions that are truly needed in order to do its job, and always aim to keep this at a minimum.
◻ Remove any unused or unnecessary dimensions.
◻ Do not add dimensions that can be referenced through a property of a dimension that is already present.
◻ Prefer mapped dimensions or dimension replacement instead of adding extra dimensions.
◻ Use subsets or smaller mapped lists when only a portion of a list is relevant.
See these resources on the Pigment Knowledge Base and Community for more details on how to leverage each of these features.

