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

asynchronously fetch token data #872

Merged
merged 3 commits into from
Jun 29, 2020
Merged

asynchronously fetch token data #872

merged 3 commits into from
Jun 29, 2020

Conversation

bh2smith
Copy link
Contributor

@bh2smith bh2smith commented Jun 26, 2020

The previous implementation was naive and this one is much much faster!

closes #868 (Note that it was suggested to use web3-BatchRequest, but this is efficient as is and the web3 option seems to require passing around additional artifacts).

Test Plan
Can't really be tested without a wrapper script. The only script using this within the project is scripts/ensure_owl_liquidity.ts

@bh2smith bh2smith requested review from a team and fedgiac June 26, 2020 13:35
Copy link
Contributor

@fedgiac fedgiac 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!

This would be a perfect candidate to test out batch web3 requests at some point.

Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
@bh2smith
Copy link
Contributor Author

This would be a perfect candidate to test out batch web3 requests at some point.

Yes! I had forgotten. Maybe I should do that now!

Copy link
Contributor

@fleupold fleupold left a comment

Choose a reason for hiding this comment

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

The previous implementation was naive and this one is much much faster!

Would be awesome to quantify how much faster - maybe just using the unix time tool before and after to get an idea.

@bh2smith
Copy link
Contributor Author

bh2smith commented Jun 29, 2020

@fleupold

This would be a perfect candidate to test out batch web3 requests at some point.

Old Script:
Fetching info for 18 tokens
Execution Time: 66.557 seconds

New Script:
Fetching info for 18 tokens
Execution Time: 3.478 seconds

Appears to be about 22x faster.

This was executed with the following script:

import { fetchTokenInfoFromExchange } from "../src/fee_token_liquidity";
import { getBatchExchange } from "./util";

module.exports = async (callback: Truffle.ScriptCallback) => {
  try {
    const exchange = await getBatchExchange(artifacts);
    const numTokens = (await exchange.numTokens()).toNumber();
    const tokens = Array(numTokens)
      .fill(0)
      .map((_, i) => i);
    console.log(`Fetching info for ${numTokens} tokens`);
    console.time("Execution Time");
    await fetchTokenInfoFromExchange(exchange, tokens, artifacts);
    console.timeEnd("Execution Time");
    callback();
  } catch (error) {
    callback(error);
  }
};

using

npx truffle exec build/common/scripts/test_script.js --network rinkeby

@bh2smith bh2smith merged commit 1197a98 into master Jun 29, 2020
@bh2smith bh2smith deleted the async_token_fetching branch June 29, 2020 13:14
@fleupold
Copy link
Contributor

Awesome speed improvement!

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.

Await Token Info in Parallel
3 participants