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

Fix race conditions in methods with arguments #255

Merged
merged 1 commit into from Dec 17, 2021

Conversation

JacobEvelyn
Copy link
Member

This commit fixes race conditions found in memoized methods
that take arguments. This comes at a slight performance cost
for truthy memoized values (due to switching from Hash#[]
to the slightly slower Hash#fetch) but will be faster when
memoized values are falsey.

This change removes the "truthy optimization" leading to these
race conditions and as a result allows us to simplify our
benchmark code as we no longer need to benchmark truthy and
falsey values separately.

Before merging:

  • Copy the table printed at the end of the latest benchmark results into the README.md and update this PR
  • If this change merits an update to CHANGELOG.md, add an entry following Keep a Changelog guidelines with semantic versioning

@codecov
Copy link

codecov bot commented Dec 17, 2021

Codecov Report

Merging #255 (88997be) into main (b3dae0e) will not change coverage.
The diff coverage is n/a.

❗ Current head 88997be differs from pull request most recent head 77743aa. Consider uploading reports for the commit 77743aa to get more accurate results
Impacted file tree graph

@@            Coverage Diff            @@
##              main      #255   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          167       167           
=========================================
  Hits           167       167           
Impacted Files Coverage Δ
lib/memo_wise.rb 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b3dae0e...77743aa. Read the comment docs.

README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@ms-ati ms-ati left a comment

Choose a reason for hiding this comment

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

LGTM

This commit fixes race conditions found in memoized methods
that take arguments. This comes at a slight performance cost
for truthy memoized values (due to switching from `Hash#[]`
to the slightly slower `Hash#fetch`) but will be faster when
memoized values are falsey.

This change removes the "truthy optimization" leading to these
race conditions and as a result allows us to simplify our
benchmark code as we no longer need to benchmark truthy and
falsey values separately.
@JacobEvelyn JacobEvelyn merged commit e75c27b into main Dec 17, 2021
@JacobEvelyn JacobEvelyn deleted the thread-safety-improvements branch December 17, 2021 18:01
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.

None yet

2 participants