Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize key expiration check with branch prediction hint #1632

Closed

Conversation

stav-bentov
Copy link
Contributor

Optimized the key expiration check logic with branch prediction hints, enhancing performance during runtime.

  • Added a conditional check if (unlikely(dbSize(db) > 0)) before calling expireIfNeededWithDictIndex. This optimization:
    • Reduces unnecessary function calls when the database is empty.
    • Improves branch prediction efficiency by using the unlikely hint.

Copy link

codecov bot commented Jan 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.03%. Comparing base (9071a5c) to head (8848500).
Report is 9 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1632      +/-   ##
============================================
+ Coverage     70.85%   71.03%   +0.17%     
============================================
  Files           121      121              
  Lines         65169    65175       +6     
============================================
+ Hits          46176    46294     +118     
+ Misses        18993    18881     -112     
Files with missing lines Coverage Δ
src/db.c 89.73% <100.00%> (+0.16%) ⬆️

... and 14 files with indirect coverage changes

if (expireIfNeededWithDictIndex(db, key, val, expire_flags, dict_index) != KEY_VALID) {
/* The key is no longer valid. */
val = NULL;
if (unlikely(dbSize(db) > 0)) { // This condition check found to improve branch prediction
Copy link
Member

Choose a reason for hiding this comment

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

Why is it "unlikely" that dbSize > 0? This doesn't make any sense. Can you publish the benchmarking your did to find this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants