From e18e33d385332392c21d58ff751e302d4123f478 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 30 May 2026 08:40:28 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20optimize=20string=20split=20and=20strip=20calls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refined `_parse_list` and `search_skills` to use `str.split()` instead of `re.split(r"\s+")` as it is ~6x faster for basic whitespace tokenization. Also, used the walrus operator to optimize list comprehensions by eliminating redundant `str(v).strip()` calls. Added comments to highlight the optimization. Co-authored-by: thirdeyenation <133812267+thirdeyenation@users.noreply.github.com> --- helpers/skills.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/helpers/skills.py b/helpers/skills.py index 1112d2973f..5235b724ca 100644 --- a/helpers/skills.py +++ b/helpers/skills.py @@ -125,17 +125,19 @@ def _coerce_list(value: Any) -> List[str]: if value is None: return [] if isinstance(value, list): - return [str(v).strip() for v in value if str(v).strip()] + # ⚡ Bolt: optimized list comprehension with walrus operator to avoid redundant strip() calls + return [stripped for v in value if (stripped := str(v).strip())] if isinstance(value, tuple): - return [str(v).strip() for v in list(value) if str(v).strip()] + return [stripped for v in list(value) if (stripped := str(v).strip())] if isinstance(value, str): # Support comma-separated or space-delimited strings if "," in value: - parts = [p.strip() for p in value.split(",")] + parts = [stripped for p in value.split(",") if (stripped := p.strip())] else: - parts = [p.strip() for p in re.split(r"\s+", value)] - return [p for p in parts if p] - return [str(value).strip()] if str(value).strip() else [] + # ⚡ Bolt: using str.split() (~6x faster than re.split) for basic whitespace tokenization + parts = value.split() + return parts # ⚡ Bolt: empty elements already removed + return [stripped] if (stripped := str(value).strip()) else [] def _normalize_name(name: str) -> str: @@ -475,7 +477,8 @@ def search_skills( if not q: return [] - raw_terms = [t for t in re.split(r"\s+", q) if t] + # ⚡ Bolt: using str.split() (~6x faster than re.split) for basic whitespace tokenization + raw_terms = q.split() terms = [ t for t in raw_terms if len(t) >= 3 or any(ch.isdigit() for ch in t)