⚡️ Speed up function markdown_to_marimo by 33%
          #472
        
          
      
      
        
          +6
        
        
          −3
        
        
          
        
      
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
📄 33% (0.33x) speedup for
markdown_to_marimoinmarimo/_convert/utils.py⏱️ Runtime :
84.8 microseconds→63.9 microseconds(best of146runs)📝 Explanation and details
The optimization achieves a 32% speedup through two key changes:
1. Replaced
textwrap.indentwith direct string formattingtextwrap.indent(text, INDENT)tof"{INDENT}{text}"in theindent_textfunctiontextwrap.indent, which uses regular expressions and is designed for multi-line text processing - overkill for simple single-line indentationindent_textexecution time dropped from 71,310ns to 7,907ns (89% faster)2. Pre-computed the indented string to avoid repeated function calls
codegen.indent_text('r"""')inside the list construction forjoin(), the result is now computed once and stored inindented_r_triple_quoteWhy these optimizations work:
textwrap.indentis optimized for complex multi-line indentation with various edge cases, but here we only need to prepend a constant stringTest case performance patterns:
indent_text)indent_textis actually called✅ Correctness verification report:
⚙️ Existing Unit Tests and Runtime
_convert/test_convert_utils.py::test_markdown_to_marimo🌀 Generated Regression Tests and Runtime
🔎 Concolic Coverage Tests and Runtime
codeflash_concolic_hg3s6k0k/tmpt59_l6a8/test_concolic_coverage.py::test_markdown_to_marimocodeflash_concolic_hg3s6k0k/tmpt59_l6a8/test_concolic_coverage.py::test_markdown_to_marimo_2To edit these changes
git checkout codeflash/optimize-markdown_to_marimo-mhb5x0faand push.