mirror of
https://github.com/baz-scm/awesome-reviewers.git
synced 2025-08-20 18:58:52 +03:00
1.5 KiB
1.5 KiB
title, description, repository, label, language, comments_count, repository_stars
| title | description | repository | label | language | comments_count | repository_stars |
|---|---|---|---|---|---|---|
| Cache expensive computed values | Cache frequently accessed or computed values to avoid redundant calculations and property lookups. This applies to: 1. Loop invariant values 2. Expensive computations | microsoft/typescript | Performance Optimization | TypeScript | 4 | 105378 |
Cache frequently accessed or computed values to avoid redundant calculations and property lookups. This applies to:
- Loop invariant values
- Expensive computations
- Repeated property access
- Function call results
Example - Before:
while (index < path.length) {
// path.length accessed on every iteration
if (path.indexOf(separator, index) !== -1) {
// indexOf called multiple times
}
}
Example - After:
const pathLength = path.length; // Cache loop invariant
const separatorIndex = path.indexOf(separator, index); // Cache computation
while (index < pathLength) {
if (separatorIndex !== -1) {
// Use cached values
}
}
This optimization is particularly important in performance-critical paths and loops. When implementing, consider:
- Caching loop invariants outside the loop
- Storing repeated computation results in local variables
- Caching property accesses that won't change during execution
- Using local variables for values accessed multiple times
The performance impact can be significant, especially when the cached values are used frequently or the computations are expensive.