Skip to content

Optimize eoRanking: Add caching and index vector#80

Merged
nojhan merged 15 commits intonojhan:masterfrom
Alessandro624:feat-eo-ranking-ale
Apr 15, 2025
Merged

Optimize eoRanking: Add caching and index vector#80
nojhan merged 15 commits intonojhan:masterfrom
Alessandro624:feat-eo-ranking-ale

Conversation

@Alessandro624
Copy link
Contributor

This PR improves the performance of the eoRanking class by introducing two key enhancements:

  • Cached Coefficients:

    • Precomputes and stores intermediate constants (e.g., alpha, beta, gamma).

    • These are recomputed only when the population size changes, improving runtime efficiency for repeated evaluations.

  • Index Vector:

    • Replaces the costly lookfor loop with a std::vector for O(1) lookup of individual indices.

    • This avoids potential runtime errors and simplifies the ranking logic.

Fully preserves compatibility with the EO framework (eoPerf2Worth, eoPop).

@nojhan nojhan self-requested a review April 14, 2025 19:09
Copy link
Owner

@nojhan nojhan left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! This is a neat feature, which we must include in Paradiseo.

However, adding a cache system rely on the idea that the instantiated operator is always used in the same context. In the case of automated design, this is not always the case. Thus, I think this class should either:

  • be a new class, like eoRankingCached,
  • have a configurable cache, with the cache disabled by default.

I would also like to have more comments, given that the system is not immediately obvious to the reader. Something like starting from the PR message and extend a bit, in the class' header, perhaps?

Finally, a simple test ensuring that both implementations produces the same result would be a convincing check that everything is perfectly working.

@nojhan nojhan self-assigned this Apr 14, 2025
@Alessandro624
Copy link
Contributor Author

Thank you for your review and suggestions. I've implemented the requested changes:

  • Created a separate eoRankingCached class to maintain clear separation from the original implementation

  • Added more comments including:

    • Detailed class header comments explaining the caching mechanism

    • Usage guidelines

    • Clear warning about constant population size requirement

  • Implemented some tests that verifies:

    • Identical results between cached and original versions

    • Edge case handling (including minimum population size)

@Alessandro624 Alessandro624 requested a review from nojhan April 15, 2025 08:04
Copy link
Owner

@nojhan nojhan left a comment

Choose a reason for hiding this comment

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

Impressive work!

Apart from the very minor comments, I think it would be better if we had those two classes in two separate files. I know it's not always the case in all the old codebase, but I think that would really help discoverability, for users who look at files directly.

Also, the indentation seems to be inconsistent, with sometime two spaces, sometime four. I think four is more or less the standard in Paradiseo (even if we have mixed styles…).

@Alessandro624
Copy link
Contributor Author

Thank you for your review and valuable feedback. I have implemented both of your requested changes:

  • Separated the classes into individual files to improve code organization and discoverability

  • Standardized the indentation to use 4 spaces consistently throughout

Additionally, the newly added test cases confirm that all assertions are functioning as intended.

@Alessandro624 Alessandro624 requested a review from nojhan April 15, 2025 13:48
Copy link
Owner

@nojhan nojhan left a comment

Choose a reason for hiding this comment

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

Almost perfect! I'm just nitpicking about asserts, but once fixed, I will merge. I tested locally, and everything merges well and passes tests.

@nojhan
Copy link
Owner

nojhan commented Apr 15, 2025

Also, don't forget to "resolve conversations" that are fixed in further commits.

Copy link
Owner

@nojhan nojhan left a comment

Choose a reason for hiding this comment

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

Just a last inconsistency.

Copy link
Owner

@nojhan nojhan left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks for the contribution!

@nojhan nojhan merged commit c660489 into nojhan:master Apr 15, 2025
11 checks passed
@Alessandro624
Copy link
Contributor Author

Thanks for the detailed feedback and suggestions!

@nojhan
Copy link
Owner

nojhan commented Apr 15, 2025

No problem. I'm looking forward for the next contribution ;-) And I hope you find Paradiseo useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants