Skip to content

Conversation

@benshush
Copy link
Contributor

@benshush benshush commented Feb 16, 2025

Project Robyn

Summary

This PR optimizes _geometric_adstock, the main performance bottleneck, reducing its execution time by ~99% and improving the total model train time by ~40% on Python version.

Fixes

This PR does not address an existing GitHub issue but significantly improves performance.

Type of change

  • fix: Performance optimization (non-breaking change that improves efficiency)
  • test: Added unit test to validate correctness

Motivation & Context

  • _geometric_adstock previously accounted for 39% of the total model train time, significantly slowing down model execution.
  • This function was rewritten using scipy.signal.lfilter, replacing a Python loop with a highly efficient SciPy-based implementation (built on NumPy).
  • This change improves execution time from 108.9s → 0.495s (~99% speedup), leading to an overall app model train time reduction of ~40%.

Performance Benchmark (tutorial1.ipynb, Trial=1, iterations=2000)

Before Optimization:

  • _geometric_adstock: 108.9s (39% of total model train time)
  • Total model train time: 277.9s

After Optimization:

  • _geometric_adstock: 0.495s (99% faster)
  • Total model train time: 166.7s (40% faster)

…~40%

- Replaced loop-based implementation with `scipy.signal.lfilter`
- Improved `_geometric_adstock` execution time from **108.9s → 0.495s** (~99% faster) per trial
- Reduced overall app runtime from **~277.9s → ~166.7s** (~40% speedup) per trial
- Added unit test to ensure numerical correctness (`np.allclose`)
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 16, 2025
@benshush benshush changed the title Optimize _geometric_adstock for 99% function speedup, reducing total model train time by ~40% Optimize _geometric_adstock for 99% function speedup, reducing total model train time by ~40% - Python version Feb 17, 2025
@alxlyj alxlyj self-requested a review February 25, 2025 20:24
Copy link
Contributor

@alxlyj alxlyj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me - thanks!

@alxlyj alxlyj merged commit 722d1bf into facebookexperimental:main Feb 25, 2025
1 check passed
@benshush benshush deleted the optimize-adstock branch March 15, 2025 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants