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

Performance improvements in core library #1683

Merged
merged 13 commits into from
Sep 12, 2024
Merged

Performance improvements in core library #1683

merged 13 commits into from
Sep 12, 2024

Conversation

nfcampos
Copy link
Contributor

  • Avoid creating new callback manager when received one as arg
  • Avoid looking for config when already received one as arg
  • Avoid copies of values in ensure_config/merge_configs
  • Implement version of ensure_config that accepts multiple configs (avoids calling merge_configs first)
  • Avoid calling merge_configs when we only need to attach extra tags/metadata

@@ -46,6 +46,8 @@
from langgraph.pregel.types import All, PregelExecutableTask, PregelTask
from langgraph.utils.config import merge_configs, patch_config

EMPTY_SEQ = tuple()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have an idea of how helpful this was? I guess this is sort of an inner loop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was more because the previous code was actually incorrect, as it could end up trying to do <str> in None

checkpoint["channel_versions"][chan] = get_next_version(
max_version, channels[chan]
)
if channels[chan].consume() and get_next_version is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

is this just stylistic or does it actually improve perf?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No this was just style

@@ -97,6 +97,9 @@ def __radd__(self, other: dict[str, Any]) -> "AddableUpdatesDict":
raise TypeError("AddableUpdatesDict does not support right-side addition")


EMPTY_SEQ = tuple()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we just make a single empty_seq in an internal _constants file or something

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 guess so?

- Avoid creating new callback manager when received one as arg
- Avoid looking for config when already received one as arg
- Avoid copies of values in ensure_config/merge_configs
- Implement version of ensure_config that accepts multiple configs (avoids calling merge_configs first)
- Avoid calling merge_configs when we only need to attach extra tags/metadata
@nfcampos nfcampos merged commit 8f87cd1 into main Sep 12, 2024
54 checks passed
@nfcampos nfcampos deleted the nc/11sep/perf branch September 12, 2024 18:01
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.

2 participants