Skip to content

optimize calculation skipping redundant system calls#316

Open
Warkanlock wants to merge 5 commits into
ScienceBasedTargets:mainfrom
Warkanlock:sbti-local-file-integration
Open

optimize calculation skipping redundant system calls#316
Warkanlock wants to merge 5 commits into
ScienceBasedTargets:mainfrom
Warkanlock:sbti-local-file-integration

Conversation

@Warkanlock
Copy link
Copy Markdown

@Warkanlock Warkanlock commented Nov 22, 2023

chore(sbti): optimize calculation skipping redundant system calls

Introduction

This PR introduces an optimization to the tool's file-handling logic. Specifically, it modifies the behavior around the output.write() call and the request to the dashboard to prevent unnecessary file writes. This change also avoids requesting the server if the file is already on the disk.

  1. This change checks if the required file is already present locally. If so, it skips the write operation, speeding up the overall calculation. (avoiding the hops)
  2. Additionally, this modification makes the tool compatible with environments that usually have an NFTS/FAT file storage as read-only.
  3. This change also makes integrating the library into a serverless AWS Lambda Container possible.

Changes

Introduces two new variables inside config.py

class PortfolioCoverageTVPConfig(PortfolioAggregationConfig):
    FILE_TARGETS_CUSTOM_PATH = None
    USE_LOCAL_CTA = False
    USE_CUSTOM_FILE_TARGETS_PATH = False

Also individually, we can use

class PortfolioCoverageTVPConfig(PortfolioAggregationConfig):
    SKIP_CTA_FILE_IF_EXISTS = False

to avoid the creation or request of files while we have it on disk

Compatibility

It won't change the previous behavior of the library, and if those configurations are not set, it works just as before

Integration

I'm integrating these modifications into a container using the modified library, and it works so far, bringing down responses from 4 seconds to ~1.5 for a remote serverless call.

Trade-off

Must take into account the user's ability to always download the file and keep track of updates if there are any.

@Warkanlock Warkanlock changed the title chore(sbti): optimize calculation skipping redundant system calls optimize calculation skipping redundant system calls Nov 22, 2023
@mountainrambler
Copy link
Copy Markdown
Contributor

Thank you for this PR. I think it looks good. There is one thing that maybe we should consider and which relates to your Trade-off above. Perhaps the code should check if the CTA file is more than one week old, and if it is, the user should be warned and allowed to manually or automatically fetch a new CTA file. The SBTi currently updates the CTA file on a weekly basis. (Maybe in the future we will see a JSON api instead of the excel-based solution).

@Warkanlock
Copy link
Copy Markdown
Author

Thank you for this PR. I think it looks good. There is one thing that maybe we should consider and which relates to your Trade-off above. Perhaps the code should check if the CTA file is more than one week old, and if it is, the user should be warned and allowed to manually or automatically fetch a new CTA file. The SBTi currently updates the CTA file on a weekly basis. (Maybe in the future we will see a JSON api instead of the excel-based solution).

That's a great idea. I'll do it

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.

3 participants