Skip to content

Speed up client initialization with lazy loading #473

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

Draft
wants to merge 23 commits into
base: release-candidate/2025-04
Choose a base branch
from

Conversation

jhamon
Copy link
Collaborator

@jhamon jhamon commented Apr 8, 2025

Problem

In the upcoming release we want to take a dependency on the Assistants plugin. But we don't want this dependency to come at a cost of degraded performance for users who are not using the features in the plugin.

Solution

To accomplish these goals I wanted to do some significant refactoring without breaking any existing functionality.

  • Existing integration tests need to pass without major modification

Initialization performance

To assess the load time for the pinecone package, I used a built-in package called importtime.

poetry run python3 -X importtime -c "from pinecone import Pinecone; pc = Pinecone(api_key='foo')" 2> main.log

Then I visualized the results using a new dev-dependency called tuna

poetry run tuna main.log

These steps can be used to show that before any refactoring, the initialization time was more than 300ms(!)

Screenshot 2025-05-08 at 3 20 27 PM

After refactoring to make PluginAware lazy, and also restructure code related to operations on indexes, collections, inference, etc to take advantage of lazy loading we can improve the client initialization time very significantly. This is a big improvement because it means users will no longer need to wait to load a bunch of code for features they are not using.

Screenshot 2025-05-08 at 3 18 16 PM

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)
  • This change requires a documentation update
  • Infrastructure change (CI configs, etc)
  • Non-code change (docs, etc)
  • None of the above: (explain here)

Test Plan

Describe specific steps for validating this change.

@jhamon jhamon force-pushed the jhamon/client-reorg branch from b89d903 to cd15bf9 Compare April 25, 2025 18:42
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.

1 participant