Skip to content

Commit 79b58ce

Browse files
authored
Fix varmap to apply func before recursion (#1593)
* Fix varmap to apply func before recursion * CHANGELOG
1 parent 02ed26d commit 79b58ce

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

‎CHANGELOG.asciidoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ endif::[]
2929
//===== Bug fixes
3030
//
3131
32+
=== Unreleased
33+
34+
// Unreleased changes go here
35+
// When the next release happens, nest these changes under the "Python Agent version 6.x" heading
36+
//[float]
37+
//===== Features
38+
//
39+
[float]
40+
===== Bug fixes
41+
42+
* Fixed a performance issue for local variable shortening via `varmap()` {pull}1593[#1593]
43+
44+
3245
[[release-notes-6.x]]
3346
=== Python Agent version 6.x
3447

‎elasticapm/utils/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ def varmap(func, var, context=None, name=None, **kwargs):
6464
return func(name, "<...>", **kwargs)
6565
context.add(objid)
6666
if isinstance(var, dict):
67+
# Apply func() before recursion, so that `shorten()` doesn't have to iterate over all the trimmed values
68+
ret = func(name, var, **kwargs)
6769
# iterate over a copy of the dictionary to avoid "dictionary changed size during iteration" issues
68-
ret = func(name, dict((k, varmap(func, v, context, k, **kwargs)) for k, v in var.copy().items()), **kwargs)
70+
ret = dict((k, varmap(func, v, context, k, **kwargs)) for k, v in ret.copy().items())
6971
elif isinstance(var, (list, tuple)):
70-
ret = func(name, [varmap(func, f, context, name, **kwargs) for f in var], **kwargs)
72+
# Apply func() before recursion, so that `shorten()` doesn't have to iterate over all the trimmed values
73+
ret = func(name, var, **kwargs)
74+
ret = [varmap(func, f, context, name, **kwargs) for f in ret]
7175
else:
7276
ret = func(name, var, **kwargs)
7377
context.remove(objid)

0 commit comments

Comments
 (0)