Back to all reviewers

Avoid optimization anti-patterns

discourse/discourse
Based on 3 comments
Other

Identify and eliminate code patterns that appear to be performance optimizations but actually hurt performance or negate their intended benefits. Common anti-patterns include:

Performance Optimization Other

Reviewer Prompt

Identify and eliminate code patterns that appear to be performance optimizations but actually hurt performance or negate their intended benefits. Common anti-patterns include:

  1. Ineffective debouncing: Cancelling debounce timers immediately before setting new ones defeats the purpose of debouncing and can lead to excessive function calls.

  2. Misused performance decorators: Using decorators like @cached when a native getter would suffice can introduce negative performance implications in modern frameworks.

  3. Excessive component instantiation: Rendering patterns that create unnecessary component instances (e.g., rendering every placeholder in every position) waste resources and hurt performance.

Example of debouncing anti-pattern:

// Anti-pattern: Cancelling debounce immediately
if (this.searchTimer) {
  cancel(this.searchTimer); // This negates debouncing benefits
}
this.searchTimer = discourseDebounce(this, this._performSearch, 300);

// Better: Let debounce handle the timing
this.searchTimer = discourseDebounce(this, this._performSearch, 300);

Before implementing performance optimizations, verify they actually provide the intended benefit and don’t introduce overhead that outweighs their advantages. Profile and measure the impact of optimization patterns to ensure they deliver real performance improvements.

3
Comments Analyzed
Other
Primary Language
Performance Optimization
Category

Source Discussions