mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
perf(core_helpers): fast-path dicts and lists in the checked JSON helpers
as_str_mapping now tries the concrete dict check before the Mapping ABC check, and iter_items returns lists before the runtime-checkable Protocol check. Both return the same object as before, and roughly halve the overhead CodSpeed flagged on the A2A text-extraction benchmarks.
This commit is contained in:
parent
5815c092f0
commit
463e3ccdf7
1 changed files with 4 additions and 1 deletions
|
|
@ -102,7 +102,7 @@ _LAX_BOOL: Final = TypeAdapter(bool)
|
|||
|
||||
|
||||
def as_str_mapping(value: object) -> Mapping[str, object] | None:
|
||||
return value if isinstance(value, Mapping) else None
|
||||
return value if isinstance(value, (dict, Mapping)) else None
|
||||
|
||||
|
||||
def as_object_list(value: object) -> Sequence[object] | None:
|
||||
|
|
@ -174,6 +174,9 @@ def keyword_arguments(value: object, target: type[object]) -> KeywordArguments:
|
|||
|
||||
|
||||
def iter_items(value: object) -> Iterable[object]:
|
||||
listed: Final = as_object_list(value)
|
||||
if listed is not None:
|
||||
return listed
|
||||
if isinstance(value, _SupportsIter):
|
||||
return value
|
||||
if isinstance(value, _SupportsGetItem):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue