Skip to content

⚡️ Speed up function sanitize_query_string by 279% in PR #11689 (aka/traces-v0)#11945

Closed
codeflash-ai[bot] wants to merge 72 commits into
mainfrom
codeflash/optimize-pr11689-2026-02-28T02.07.34
Closed

⚡️ Speed up function sanitize_query_string by 279% in PR #11689 (aka/traces-v0)#11945
codeflash-ai[bot] wants to merge 72 commits into
mainfrom
codeflash/optimize-pr11689-2026-02-28T02.07.34

Conversation

@codeflash-ai
Copy link
Copy Markdown
Contributor

@codeflash-ai codeflash-ai Bot commented Feb 28, 2026

⚡️ This pull request contains optimizations for PR #11689

If you approve this dependent PR, these changes will be merged into the original PR branch aka/traces-v0.

This PR will be automatically closed if the original PR is merged.


📄 279% (2.79x) speedup for sanitize_query_string in src/backend/base/langflow/services/tracing/validation.py

⏱️ Runtime : 40.7 milliseconds 10.7 milliseconds (best of 76 runs)

📝 Explanation and details

The optimized code achieves a 279% speedup (from 40.7ms to 10.7ms) by replacing a character-by-character Python generator expression with a pre-compiled regular expression that operates in optimized C code.

Key Changes:

  1. Pre-compiled regex pattern (_NON_PRINTABLE_RE): Compiled once at module import, this regex matches sequences of non-printable characters ([^\x20-\x7E]+) and removes them in a single optimized operation. The line profiler shows this drops from 196ms (99.7% of time) to just 12.3ms (94.3% of time).

  2. Fast-path for empty strings: The explicit if value == "" check avoids unnecessary regex work for empty inputs, returning None immediately.

Why This Is Faster:

  • Generator overhead eliminated: The original "".join(ch for ch in value if " " <= ch <= "~") creates a generator object, iterates character-by-character in Python bytecode, performs a comparison for each character, and builds intermediate string objects. This is pure Python-level work.

  • Regex operates in C: The re.sub() call hands the entire string to highly optimized C code that scans and filters in a single pass with minimal Python object creation. Regular expression engines are designed for exactly this kind of bulk pattern matching.

  • Reduced memory churn: The generator/join approach creates many intermediate Python objects during iteration. The regex performs the same filtering with far fewer allocations.

Impact on Workloads:

  • Best for: Strings with many printable characters (typical query strings, URLs, JSON) where the regex can quickly scan and copy valid ranges. Test cases like test_large_string_within_limit and test_repeated_pattern_large demonstrate consistent speedups on realistic inputs.

  • Also benefits: Strings with many non-printable characters to filter (e.g., test_large_string_mostly_invalid), as the regex efficiently skips invalid character runs rather than checking each one individually.

  • Minimal overhead added: The empty string fast-path and one-time regex compilation at import add negligible cost while preserving exact behavioral compatibility (all tests pass identically).

This optimization is particularly valuable if sanitize_query_string is called frequently in request processing pipelines, as the per-call savings compound across many invocations.

Correctness verification report:

Test Status
⚙️ Existing Unit Tests 23 Passed
🌀 Generated Regression Tests 570 Passed
⏪ Replay Tests 🔘 None Found
🔎 Concolic Coverage Tests 🔘 None Found
📊 Tests Coverage 100.0%
⚙️ Click to see Existing Unit Tests
🌀 Click to see Generated Regression Tests
import pytest  # used for our unit tests
from langflow.services.tracing.validation import sanitize_query_string


def test_none_input_returns_none():
    # None should be passed through and return None (explicit check in function)
    codeflash_output = sanitize_query_string(None)


def test_basic_strip_and_remove_controls():
    # Input contains printable chars, spaces, and control characters (\n, \t).
    raw = "  hello\nworld\t!  "
    # Newline and tab are removed; leading/trailing spaces are stripped.
    codeflash_output = sanitize_query_string(raw)


def test_truncates_to_custom_max_len():
    # Create a long printable string and ensure custom max_len truncates it.
    raw = "a" * 30  # 30 'a' characters
    # Truncate to 10 characters explicitly
    codeflash_output = sanitize_query_string(raw, max_len=10)
    # Also check default truncation at 50 doesn't modify this short input
    codeflash_output = sanitize_query_string(raw)


def test_empty_string_returns_none():
    # Empty input becomes cleaned == "" and function should return None
    codeflash_output = sanitize_query_string("")


def test_only_non_printable_characters_returns_none():
    # Only control characters should be stripped away leaving nothing -> None
    codeflash_output = sanitize_query_string("\n\r\t\x00\x1F")


def test_rejects_non_ascii_characters_but_keeps_ascii_portion():
    # Mixed string with ASCII letters, accented letters, and emoji.
    raw = "café😊!"  # 'é' and emoji are outside the accepted range and should be removed
    # Expected: only ASCII printable characters remain ('c','a','f','!').
    codeflash_output = sanitize_query_string(raw)


def test_accepts_full_printable_ascii_range_and_strips_spaces():
    # Build the full range of printable ASCII from space (0x20) to tilde (0x7E)
    printable = "".join(chr(i) for i in range(0x20, 0x7F))
    # The function strips leading/trailing spaces, so expect printable.strip()
    codeflash_output = sanitize_query_string(printable)
    # If we set a smaller max_len, the result is truncated accordingly
    expected_truncated = printable.strip()[:5]
    codeflash_output = sanitize_query_string(printable, max_len=5)


def test_max_len_zero_returns_empty_string_when_cleaned_nonempty():
    # When max_len is 0, slicing returns an empty string (''), not None,
    # provided there was at least one acceptable character before slicing.
    codeflash_output = sanitize_query_string("abc", max_len=0)


def test_negative_max_len_slices_correctly():
    # Negative max_len should act like a negative slice (e.g., -1 drops last character)
    codeflash_output = sanitize_query_string("abcdef", max_len=-1)
    # If negative slice still yields an empty string (e.g., max_len <= -len(cleaned)),
    # the function will return that empty string (not None), consistent with slicing behavior.
    codeflash_output = sanitize_query_string("ab", max_len=-5)


def test_large_input_deterministic_and_repeatable():
    # Build a large input ~1000 characters mixing printable and control characters.
    parts = []
    for i in range(1000):
        # Every 10th character insert a newline (to be removed); otherwise a printable char.
        if i % 10 == 0:
            parts.append("\n")
        # Use a repeating printable range to ensure only printable ASCII are kept
        parts.append(chr(32 + (i % 95)))  # 95 printable characters from 0x20 to 0x7E inclusive
    large_input = "".join(parts)

    # Compute expected result deterministically (this mirrors the function's documented behavior).
    expected_cleaned = "".join(ch for ch in large_input if " " <= ch <= "~").strip()
    # Truncate for a reasonably sized comparison in repeated calls
    max_len = 100
    expected_truncated = expected_cleaned[:max_len] if expected_cleaned else None

    # Call sanitize_query_string repeatedly to ensure stable output and acceptable performance.
    for _ in range(500):  # 500 iterations is within the required "up to 1000" limit
        codeflash_output = sanitize_query_string(large_input, max_len=max_len); result = codeflash_output

    # Final sanity checks: result is either None or str as documented
    codeflash_output = sanitize_query_string(large_input, max_len=max_len); final_result = codeflash_output
# codeflash_output is used to check that the output of the original code is the same as that of the optimized code.
#------------------------------------------------
import pytest
from langflow.services.tracing.validation import sanitize_query_string


def test_basic_printable_string():
    """Test that a normal printable ASCII string is returned unchanged."""
    codeflash_output = sanitize_query_string("hello world"); result = codeflash_output


def test_basic_alphanumeric_string():
    """Test that alphanumeric strings are preserved."""
    codeflash_output = sanitize_query_string("abc123XYZ"); result = codeflash_output


def test_basic_with_spaces():
    """Test that spaces within the string are preserved."""
    codeflash_output = sanitize_query_string("hello world test"); result = codeflash_output


def test_basic_with_special_characters():
    """Test that printable special characters (!, @, #, etc.) are preserved."""
    codeflash_output = sanitize_query_string("test@example.com"); result = codeflash_output


def test_basic_with_punctuation():
    """Test that common punctuation marks are preserved."""
    codeflash_output = sanitize_query_string("Hello, World!"); result = codeflash_output


def test_none_input_returns_none():
    """Test that None input returns None."""
    codeflash_output = sanitize_query_string(None); result = codeflash_output


def test_empty_string_returns_none():
    """Test that an empty string returns None."""
    codeflash_output = sanitize_query_string(""); result = codeflash_output


def test_whitespace_only_returns_none():
    """Test that a string with only whitespace returns None after stripping."""
    codeflash_output = sanitize_query_string("   "); result = codeflash_output


def test_default_max_length_50():
    """Test that the default max_len of 50 is applied correctly."""
    long_string = "a" * 60
    codeflash_output = sanitize_query_string(long_string); result = codeflash_output


def test_custom_max_length():
    """Test that a custom max_len parameter is respected."""
    long_string = "a" * 100
    codeflash_output = sanitize_query_string(long_string, max_len=20); result = codeflash_output


def test_leading_and_trailing_whitespace_stripped():
    """Test that leading and trailing whitespace is removed."""
    codeflash_output = sanitize_query_string("   hello world   "); result = codeflash_output


def test_tab_character_removed():
    """Test that tab characters (non-printable in this range) are removed."""
    codeflash_output = sanitize_query_string("hello\tworld"); result = codeflash_output


def test_newline_character_removed():
    """Test that newline characters are removed."""
    codeflash_output = sanitize_query_string("hello\nworld"); result = codeflash_output


def test_carriage_return_removed():
    """Test that carriage return characters are removed."""
    codeflash_output = sanitize_query_string("hello\rworld"); result = codeflash_output


def test_null_character_removed():
    """Test that null bytes are removed."""
    codeflash_output = sanitize_query_string("hello\x00world"); result = codeflash_output


def test_control_characters_removed():
    """Test that various control characters are removed."""
    codeflash_output = sanitize_query_string("hello\x01\x02\x03world"); result = codeflash_output


def test_printable_characters_boundary_space_char():
    """Test the lower boundary of printable ASCII (space character 0x20)."""
    codeflash_output = sanitize_query_string(" "); result = codeflash_output


def test_printable_characters_boundary_tilde_char():
    """Test the upper boundary of printable ASCII (tilde character 0x7E)."""
    codeflash_output = sanitize_query_string("~"); result = codeflash_output


def test_just_below_printable_range():
    """Test that character just below space (0x1F) is removed."""
    codeflash_output = sanitize_query_string("hello\x1fworld"); result = codeflash_output


def test_just_above_printable_range():
    """Test that character just above tilde (0x7F, DEL) is removed."""
    codeflash_output = sanitize_query_string("hello\x7fworld"); result = codeflash_output


def test_high_ascii_characters_removed():
    """Test that high ASCII characters (128+) are removed."""
    codeflash_output = sanitize_query_string("hello\x80\x90world"); result = codeflash_output


def test_unicode_characters_removed():
    """Test that unicode characters outside ASCII range are removed."""
    codeflash_output = sanitize_query_string("hello\u00e9world"); result = codeflash_output  # é (U+00E9)


def test_emoji_removed():
    """Test that emoji characters are removed."""
    codeflash_output = sanitize_query_string("hello🌍world"); result = codeflash_output


def test_mixed_valid_and_invalid_characters():
    """Test a string with mix of valid and invalid characters."""
    codeflash_output = sanitize_query_string("test\x00data\x1f123"); result = codeflash_output


def test_all_invalid_characters_returns_none():
    """Test that a string of all invalid characters returns None."""
    codeflash_output = sanitize_query_string("\x00\x01\x02\x03"); result = codeflash_output


def test_max_len_zero():
    """Test with max_len set to 0."""
    codeflash_output = sanitize_query_string("hello", max_len=0); result = codeflash_output


def test_max_len_one():
    """Test with max_len set to 1."""
    codeflash_output = sanitize_query_string("hello world", max_len=1); result = codeflash_output


def test_max_len_equals_string_length():
    """Test when max_len exactly equals the cleaned string length."""
    codeflash_output = sanitize_query_string("hello", max_len=5); result = codeflash_output


def test_very_large_max_len():
    """Test with a very large max_len that exceeds input length."""
    codeflash_output = sanitize_query_string("hello", max_len=10000); result = codeflash_output


def test_single_character_string():
    """Test with a single valid character."""
    codeflash_output = sanitize_query_string("a"); result = codeflash_output


def test_single_invalid_character():
    """Test with a single invalid character."""
    codeflash_output = sanitize_query_string("\x00"); result = codeflash_output


def test_consecutive_spaces():
    """Test that consecutive internal spaces are preserved."""
    codeflash_output = sanitize_query_string("hello    world"); result = codeflash_output


def test_all_printable_ascii():
    """Test with all valid printable ASCII characters."""
    # Create string with all printable ASCII (space through tilde)
    all_printable = "".join(chr(i) for i in range(32, 127))
    codeflash_output = sanitize_query_string(all_printable, max_len=200); result = codeflash_output


def test_sql_query_like_string():
    """Test with a string resembling an SQL query."""
    codeflash_output = sanitize_query_string("SELECT * FROM users WHERE id=1"); result = codeflash_output


def test_url_like_string():
    """Test with a URL-like string."""
    codeflash_output = sanitize_query_string("https://example.com/path?q=test"); result = codeflash_output


def test_json_like_string():
    """Test with a JSON-like string."""
    codeflash_output = sanitize_query_string('{"key":"value"}'); result = codeflash_output


def test_parentheses_and_brackets():
    """Test that parentheses and brackets are preserved."""
    codeflash_output = sanitize_query_string("func(a, b) [0]"); result = codeflash_output


def test_mathematical_symbols():
    """Test that mathematical symbols are preserved."""
    codeflash_output = sanitize_query_string("1+2-3*4/5=6"); result = codeflash_output


def test_quotes_preserved():
    """Test that both single and double quotes are preserved."""
    codeflash_output = sanitize_query_string("'test' and \"data\""); result = codeflash_output


def test_backslash_preserved():
    """Test that backslash is preserved."""
    codeflash_output = sanitize_query_string("path\\to\\file"); result = codeflash_output


def test_forward_slash_preserved():
    """Test that forward slash is preserved."""
    codeflash_output = sanitize_query_string("path/to/file"); result = codeflash_output


def test_large_string_within_limit():
    """Test a large valid string that stays within the limit."""
    large_string = "a" * 1000
    codeflash_output = sanitize_query_string(large_string, max_len=1000); result = codeflash_output


def test_large_string_exceeding_limit():
    """Test a large valid string that exceeds the limit."""
    large_string = "a" * 10000
    codeflash_output = sanitize_query_string(large_string, max_len=100); result = codeflash_output


def test_large_string_with_many_invalid_chars():
    """Test a large string with alternating valid and invalid characters."""
    # Create a string with alternating valid (a) and invalid (\x00) chars
    mixed = "".join("a\x00" for _ in range(500))
    codeflash_output = sanitize_query_string(mixed, max_len=500); result = codeflash_output


def test_large_string_mostly_invalid():
    """Test a large string that is mostly invalid characters."""
    mostly_invalid = "\x00" * 1000 + "hello" + "\x01" * 1000
    codeflash_output = sanitize_query_string(mostly_invalid, max_len=100); result = codeflash_output


def test_large_string_with_leading_trailing_whitespace():
    """Test a large string with significant leading and trailing whitespace."""
    large_string = " " * 1000 + "content" + " " * 1000
    codeflash_output = sanitize_query_string(large_string, max_len=100); result = codeflash_output


def test_very_long_url():
    """Test with a very long URL-like string."""
    url = "https://example.com/" + "a" * 1000 + "?param=" + "b" * 1000
    codeflash_output = sanitize_query_string(url, max_len=200); result = codeflash_output


def test_repeated_pattern_large():
    """Test with a large string of repeated patterns."""
    pattern = "test_123-abc_"
    large_string = pattern * 100
    codeflash_output = sanitize_query_string(large_string, max_len=500); result = codeflash_output
    expected = large_string[:500]


def test_many_different_valid_chars_large():
    """Test with large string using many different valid characters."""
    valid_chars = "".join(chr(i) for i in range(32, 127))
    large_string = valid_chars * 50
    codeflash_output = sanitize_query_string(large_string, max_len=1000); result = codeflash_output


def test_edge_case_all_spaces_then_content():
    """Test a large string that is all spaces followed by content."""
    test_str = " " * 500 + "data"
    codeflash_output = sanitize_query_string(test_str, max_len=100); result = codeflash_output


def test_large_string_max_len_much_larger():
    """Test with max_len much larger than the actual content."""
    content = "small"
    codeflash_output = sanitize_query_string(content, max_len=10000); result = codeflash_output


def test_alternating_valid_invalid_full_range():
    """Test with alternating characters across full range boundaries."""
    test_str = "".join(chr(i) for i in range(0, 256))
    codeflash_output = sanitize_query_string(test_str, max_len=200); result = codeflash_output
    # Only printable ASCII should remain
    expected = "".join(chr(i) for i in range(32, 127))[:200]


def test_max_len_boundary_at_100():
    """Test truncation at various boundary points."""
    large = "x" * 500
    codeflash_output = sanitize_query_string(large, max_len=100); result = codeflash_output


def test_max_len_boundary_at_1000():
    """Test truncation at 1000 character boundary."""
    large = "y" * 5000
    codeflash_output = sanitize_query_string(large, max_len=1000); result = codeflash_output


def test_string_with_invalid_at_truncation_point():
    """Test that truncation happens at max_len boundary regardless of content."""
    # Create string where truncation point lands on various characters
    content = "a" * 30 + "b" * 30
    codeflash_output = sanitize_query_string(content, max_len=40); result = codeflash_output


def test_performance_many_invalid_chars_filtered():
    """Test performance with string containing many non-printable characters."""
    # String with many control characters that must be filtered out
    test_str = "".join(chr(i) for i in range(0, 32)) + "hello" + "".join(chr(i) for i in range(127, 256))
    codeflash_output = sanitize_query_string(test_str, max_len=100); result = codeflash_output


def test_whitespace_at_max_len_boundary():
    """Test when max_len boundary falls exactly at a whitespace."""
    content = "hello" + " " * 50
    codeflash_output = sanitize_query_string(content, max_len=10); result = codeflash_output
# codeflash_output is used to check that the output of the original code is the same as that of the optimized code.

To edit these changes git checkout codeflash/optimize-pr11689-2026-02-28T02.07.34 and push.

Codeflash

Adam-Aghili and others added 30 commits February 9, 2026 16:12
v0 for traces includes:
- filters: status, token usage range and datatime
- accordian rows per trace

Could add:
- more filter options. Ecamples: session_id, trace_id and latency range
add sidebar buttons for logs and trace
remove lods canvas control
hopefully fix duplicate trace ID insertion on windows
update tests and alembic tables for uts
was flow_name - trace_id
now flow_name - flow_id
address gabriel simple changes in traces.py and native.py
model name is now set using name = f"{operation} {model_name}" if model_name else operation
* feat: use uv sources for CPU-only PyTorch

Configure [tool.uv.sources] with pytorch-cpu index to avoid ~6GB CUDA
dependencies in Docker images. This replaces hardcoded wheel URLs with
a cleaner index-based approach.

- Add pytorch-cpu index with explicit = true
- Add torch/torchvision to [tool.uv.sources]
- Add explicit torch/torchvision deps to trigger source override
- Regenerate lockfile without nvidia/cuda/triton packages
- Add required-environments for multi-platform support

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: update regex to only replace name in [project] section

The previous regex matched all lines starting with `name = "..."`,
which incorrectly renamed the UV index `pytorch-cpu` to `langflow-nightly`
during nightly builds. This caused `uv lock` to fail with:
"Package torch references an undeclared index: pytorch-cpu"

The new regex specifically targets the name field within the [project]
section only, avoiding unintended replacements in other sections like
[[tool.uv.index]].

* style: fix ruff quote style

* fix: remove required-environments to fix Python 3.13 macOS x86_64 CI

The required-environments setting was causing hard failures when packages
like torch didn't have wheels for specific platform/Python combinations.
Without this setting, uv resolves optimistically and handles missing wheels
gracefully at runtime instead of failing during resolution.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
* LE-270: add fix hydration issues

* LE-270: fix disable field on max token on language model

---------

Co-authored-by: Olayinka Adelakun <olayinkaadelakun@mac.war.can.ibm.com>
* Add wait for selector in mcp server tests

* [autofix.ci] apply automated fixes

* Add more awit for selectors

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
* Reduce lag in frontend by batching react events and reducing minimval visual build time

* Cleanup

* [autofix.ci] apply automated fixes

* add tests and improve code read

* [autofix.ci] apply automated fixes

* Remove debug log

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: cristhianzl <cristhian.lousa@gmail.com>
* Lazy load imports for language model component

Ensures that only the necessary dependencies are required.
For example, if OpenAI provider is used, it will now only
import langchain_openai, rather than requiring langchain_anthropic,
langchain_ibm, etc.

* Add backwards-compat functions

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

* Add exception handling

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

* comp index

* docs: azure default temperature (#11829)

* change-azure-openai-default-temperature-to-1.0

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

* [autofix.ci] apply automated fixes (attempt 3/3)

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

* fix unit test?

* add no-group dev to docker builds

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Hamza Rashid <74062092+HzaRashid@users.noreply.github.com>
Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com>
Adam-Aghili and others added 22 commits February 27, 2026 13:32
address backend code rabbit comments
address code rabbit frontend comments
test_native_tracer minor fix address c1
address C2 + C3
address H1-H5
update test_native_tracer
address m2
address M1
fix 422 spam and clean comments
address M12
 address M3
address M4
address M5
clean up for M7, M9, M11
address L2,L4,L5 and L6 + any test
alembic + comment clean up
The optimized code achieves a **279% speedup** (from 40.7ms to 10.7ms) by replacing a character-by-character Python generator expression with a pre-compiled regular expression that operates in optimized C code.

**Key Changes:**

1. **Pre-compiled regex pattern** (`_NON_PRINTABLE_RE`): Compiled once at module import, this regex matches sequences of non-printable characters (`[^\x20-\x7E]+`) and removes them in a single optimized operation. The line profiler shows this drops from **196ms** (99.7% of time) to just **12.3ms** (94.3% of time).

2. **Fast-path for empty strings**: The explicit `if value == ""` check avoids unnecessary regex work for empty inputs, returning `None` immediately.

**Why This Is Faster:**

- **Generator overhead eliminated**: The original `"".join(ch for ch in value if " " <= ch <= "~")` creates a generator object, iterates character-by-character in Python bytecode, performs a comparison for each character, and builds intermediate string objects. This is pure Python-level work.

- **Regex operates in C**: The `re.sub()` call hands the entire string to highly optimized C code that scans and filters in a single pass with minimal Python object creation. Regular expression engines are designed for exactly this kind of bulk pattern matching.

- **Reduced memory churn**: The generator/join approach creates many intermediate Python objects during iteration. The regex performs the same filtering with far fewer allocations.

**Impact on Workloads:**

- **Best for**: Strings with many printable characters (typical query strings, URLs, JSON) where the regex can quickly scan and copy valid ranges. Test cases like `test_large_string_within_limit` and `test_repeated_pattern_large` demonstrate consistent speedups on realistic inputs.

- **Also benefits**: Strings with many non-printable characters to filter (e.g., `test_large_string_mostly_invalid`), as the regex efficiently skips invalid character runs rather than checking each one individually.

- **Minimal overhead added**: The empty string fast-path and one-time regex compilation at import add negligible cost while preserving exact behavioral compatibility (all tests pass identically).

This optimization is particularly valuable if `sanitize_query_string` is called frequently in request processing pipelines, as the per-call savings compound across many invocations.
@codeflash-ai codeflash-ai Bot added the ⚡️ codeflash Optimization PR opened by Codeflash AI label Feb 28, 2026
@github-actions github-actions Bot added the community Pull Request from an external contributor label Feb 28, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 22%
22.76% (7929/34837) 15.34% (4188/27287) 15.5% (1138/7341)

Unit Test Results

Tests Skipped Failures Errors Time
2599 0 💤 0 ❌ 0 🔥 44.732s ⏱️

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 28, 2026

Codecov Report

❌ Patch coverage is 50.43478% with 285 lines in your changes missing coverage. Please review.
✅ Project coverage is 36.53%. Comparing base (d602738) to head (db2d5fe).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
.../components/TraceComponent/FlowInsightsContent.tsx 0.00% 111 Missing ⚠️
...e/components/TraceComponent/TraceAccordionItem.tsx 0.00% 54 Missing ⚠️
...FlowPage/components/flowSidebarComponent/index.tsx 0.00% 37 Missing ⚠️
...ponents/TraceComponent/config/flowTraceColumns.tsx 0.00% 24 Missing ⚠️
...Page/components/TraceComponent/TraceDetailView.tsx 52.38% 5 Missing and 15 partials ⚠️
...Page/components/TraceComponent/traceViewHelpers.ts 84.09% 3 Missing and 11 partials ⚠️
src/frontend/src/pages/FlowPage/index.tsx 0.00% 9 Missing ⚠️
...s/TraceComponent/config/flowTraceColumnsHelpers.ts 82.75% 2 Missing and 3 partials ⚠️
...es/FlowPage/components/TraceComponent/SpanNode.tsx 85.71% 0 Missing and 4 partials ⚠️
...ontend/src/controllers/API/queries/traces/index.ts 0.00% 2 Missing ⚠️
... and 4 more

❌ Your project status has failed because the head coverage (41.46%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11945      +/-   ##
==========================================
+ Coverage   36.40%   36.53%   +0.12%     
==========================================
  Files        1570     1580      +10     
  Lines       76655    77116     +461     
  Branches    11629    11778     +149     
==========================================
+ Hits        27910    28178     +268     
- Misses      47169    47325     +156     
- Partials     1576     1613      +37     
Flag Coverage Δ
frontend 20.37% <50.43%> (+0.57%) ⬆️
lfx 41.46% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/backend/base/langflow/api/router.py 100.00% <ø> (ø)
.../backend/base/langflow/services/tracing/service.py 75.75% <ø> (-0.10%) ⬇️
src/frontend/src/components/ui/sidebar.tsx 51.63% <ø> (ø)
...rc/controllers/API/queries/traces/use-get-trace.ts 100.00% <100.00%> (ø)
...ge/components/PageComponent/MemoizedComponents.tsx 58.97% <ø> (-2.01%) ⬇️
.../pages/FlowPage/components/PageComponent/index.tsx 0.00% <ø> (ø)
...es/FlowPage/components/TraceComponent/SpanTree.tsx 100.00% <100.00%> (ø)
...ts/flowSidebarComponent/components/searchInput.tsx 0.00% <ø> (ø)
...idebarComponent/components/sidebarSegmentedNav.tsx 98.03% <100.00%> (+0.67%) ⬆️
src/frontend/src/utils/dateTime.ts 100.00% <100.00%> (ø)
... and 17 more

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codeflash-ai codeflash-ai Bot closed this Mar 2, 2026
@codeflash-ai
Copy link
Copy Markdown
Contributor Author

codeflash-ai Bot commented Mar 2, 2026

This PR has been automatically closed because the original PR #11689 by Adam-Aghili was closed.

Base automatically changed from aka/traces-v0 to main March 2, 2026 20:30
@codeflash-ai codeflash-ai Bot deleted the codeflash/optimize-pr11689-2026-02-28T02.07.34 branch March 2, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚡️ codeflash Optimization PR opened by Codeflash AI community Pull Request from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants