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

small perf improvements #1490

Merged
merged 8 commits into from
Sep 23, 2024
Merged

small perf improvements #1490

merged 8 commits into from
Sep 23, 2024

Conversation

sfc-gh-chu
Copy link
Contributor

Description

  • Fix app caching and updates sqlalchemy bulk insert api.
  • Call stack related speedups

Other details good to know for developers

Please include any other details of this change useful for TruLens developers.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to
    not work as expected)
  • New Tests
  • This change includes re-generated golden test results
  • This change requires a documentation update

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 20, 2024
@@ -378,7 +378,7 @@ def batch_insert_record(
self.orm.Record.parse(r, redact_keys=self.redact_keys)
for r in records
]
session.bulk_save_objects(records_list)
session.add_all(records_list)
Copy link
Contributor

Choose a reason for hiding this comment

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

Whats difference between add_all and bulk_save objects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Functionally the same thing. bulk_save_objects is the legacy API in SQLAlchemy 2.0 so updated this to use the add_all API.

for finfo in inspect.stack()[offset + 1 :]:
if not finfo.frame.f_globals["__name__"].startswith("trulens"):
return finfo.frame
gen = list(stack_generator(offset + 2))
Copy link
Contributor

@sfc-gh-dhuang sfc-gh-dhuang Sep 23, 2024

Choose a reason for hiding this comment

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

casting to a list shouldn't be necessary here right? and it's more memory efficient if you just iterate over the generator without forcing to evaluate the entire stack gen at once

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was originally thinking the same. Then realized that because the generator is called lazily, its call stack would change and reflect the generator callee's call stack, not the call stack of external_caller_frame

Copy link
Contributor

@sfc-gh-dhuang sfc-gh-dhuang Sep 23, 2024

Choose a reason for hiding this comment

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

ah got it sg - could you add a small comment in the code?

Copy link
Contributor Author

@sfc-gh-chu sfc-gh-chu Sep 23, 2024

Choose a reason for hiding this comment

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

actually we may be able to get around this by passing in the current frame so that inspect.currentframe() is guarenteed to be invoked at the right time (pre-generator)

@sfc-gh-dhuang
Copy link
Contributor

sfc-gh-dhuang commented Sep 23, 2024

left a few minor comments. mostly LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 23, 2024
@sfc-gh-chu sfc-gh-chu merged commit 28a0e27 into main Sep 23, 2024
7 checks passed
@sfc-gh-chu sfc-gh-chu deleted the corey/small-perf-improvements branch September 23, 2024 22:19
sfc-gh-chu added a commit that referenced this pull request Sep 25, 2024
* small perf improvements

* nonetype check

* write api

* revert

* stack_generator should take in callee's frame

* skip first
@sfc-gh-jreini sfc-gh-jreini mentioned this pull request Sep 25, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants