Skip to content

Commit

Permalink
checkpoint: Fix memory leak in checkpoint serializer (#3481)
Browse files Browse the repository at this point in the history
- Packer instances can't be kept in memory as they retain memory after
used
  • Loading branch information
nfcampos authored Feb 18, 2025
2 parents 457641f + f3a0cbf commit fc83412
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
15 changes: 3 additions & 12 deletions libs/checkpoint/langgraph/checkpoint/serde/jsonplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pathlib
import re
from collections import deque
from collections.abc import Sequence
from datetime import date, datetime, time, timedelta, timezone
from enum import Enum
from inspect import isclass
Expand All @@ -16,7 +17,7 @@
IPv6Interface,
IPv6Network,
)
from typing import Any, Callable, Optional, Sequence, Union, cast
from typing import Any, Callable, Optional, Union, cast
from uuid import UUID

import msgpack # type: ignore[import-untyped]
Expand Down Expand Up @@ -502,15 +503,5 @@ def _msgpack_ext_hook(code: int, data: bytes) -> Any:
return


ENC_POOL: deque[msgpack.Packer] = deque(maxlen=32)


def _msgpack_enc(data: Any) -> bytes:
try:
enc = ENC_POOL.popleft()
except IndexError:
enc = msgpack.Packer(default=_msgpack_default)
try:
return enc.pack(data)
finally:
ENC_POOL.append(enc)
return msgpack.packb(data, default=_msgpack_default)
2 changes: 1 addition & 1 deletion libs/checkpoint/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langgraph-checkpoint"
version = "2.0.15"
version = "2.0.16"
description = "Library with base interfaces for LangGraph checkpoint savers."
authors = []
license = "MIT"
Expand Down

0 comments on commit fc83412

Please sign in to comment.