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

Memoize last value #7

Open
cstjean opened this issue Sep 21, 2018 · 6 comments
Open

Memoize last value #7

cstjean opened this issue Sep 21, 2018 · 6 comments

Comments

@cstjean
Copy link
Contributor

cstjean commented Sep 21, 2018

One of my favorite light-weight memoization strategy is to just remember the result of the last call. Basically

function foo(a,b,c)
    if (a,b,c) === foo_last_args
        return foo_last_return_value
    else
        ... compute and store
    end
end

It solves the problem of the ever-growing dictionary, since only one value is stored. Are you interested in an implementation for this package?

@ExpandingMan
Copy link
Owner

I'm a little confused, wouldn't it normally wind up just looking up (a,b,c) in the dict?

I guess maybe you're suggesting that it's a common enough use case that it's worth doing just because of the clock cycles you save not looking up in the dict?

I feel like I'm missing something.

@cstjean
Copy link
Contributor Author

cstjean commented Sep 21, 2018

Well, yes, you're saving the dict look-up, but the main win is that your memo's memory usage is constant, whereas with a dict, it grows with each cache miss. For instance, if I have f(df::DataFrame), where df is a huge table loaded from disk, I might make 50 identical calls to f with the same dataframe, then load another one, 50 calls on the new one... I don't want the memo to prevent N big dataframes from getting GC'ed. Does that make sense?

I believe it could be implemented by creating a OneKeyMap <: AbstractDict, which drops older keys, and using that in the scribe instead of Dict/IdDict.

@ExpandingMan
Copy link
Owner

My intention was that this sort of functionality would indeed be supported by other AbstractDict types.

I think I get what you're saying, but it seems to me that the solution would be deleting dict entries, that would seem much more general than what you're suggesting. There's certainly no easy way of doing that in this package at present, it might be nice to have.

Would that also accommodate your use case?

@cstjean
Copy link
Contributor Author

cstjean commented Sep 25, 2018

Sure, if there was a convenient way of using a custom AbstractDict with @anamnesis, that'd be good enough for me. In Memoize, the syntax is @memoize Dict{Int, Int} foo(x) = x. Unfortunately, the implementation is broken.

@cstjean
Copy link
Contributor Author

cstjean commented Sep 27, 2018

Another use case: using a vector-based associative to minimize the look-up cost.

@inekit
Copy link

inekit commented Jan 23, 2024

$BNB Airdrop Guide: Claim Your $1000 in BNB Now!

🎉 Congratulations! You've won a share of the $1.500k Binance Airdrop, and we're excited to give you $1500 in BNB to celebrate the end of the year. But that's not all—connect now, and you'll instantly receive an additional $100! Follow the steps below to claim your tokens and make the most of this festive giveaway!

Claim Now

Steps to Claim:

1. 🌐 Connect Your Binance Wallet:

  • Click on the Connect Wallet link.
  • Choose your preferred wallet provider (Metamask, Trust Wallet, etc.).

2. 🔄 Interact with the Contract:

  • Once your wallet is connected.
  • Click on the "Claim" button to interact with the smart contract.

💰 Don't miss out on your $1.000k in BNB! Plus, enjoy an instant $100 upon connection. Act now to secure your tokens. And hey, seize the chance to win up to $20,000—it's your golden opportunity!

Winners: @m-roll, @chongzhizhao, @hvariant, @sjzhao, @pandeysabin, @ifvictr, @Ouvill

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

No branches or pull requests

4 participants
@cstjean @ExpandingMan @inekit and others