Performance Profiling for Step 6.2: Batch Optimization Opportunities
======================================================================

======================================================================
Profiling: Long session (5 min, typical AOI count)
  Samples: 300, AOIs: 20
======================================================================
         740455 function calls in 0.370 seconds

   Ordered by: cumulative time
   List reduced from 101 to 20 due to restriction <20>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.001    0.001    0.370    0.370 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/tracking/algorithm.py:321(compute_attention_seconds)
      300    0.003    0.000    0.369    0.001 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/tracking/algorithm.py:147(process_single_sample)
      300    0.011    0.000    0.362    0.001 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/api.py:139(find_largest_obstacle)
     6000    0.016    0.000    0.216    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:14(clip_polygon_to_wedge)
      300    0.045    0.000    0.110    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/sweep.py:393(compute_coverage)
     3963    0.045    0.000    0.094    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:115(clip_polygon_halfplane)
     2194    0.004    0.000    0.056    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/sweep.py:208(resolve_interval)
     6582    0.045    0.000    0.046    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/sweep.py:341(_find_min_distance_at_angle)
    12000    0.005    0.000    0.041    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:2241(clip)
    12000    0.006    0.000    0.036    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:51(_wrapfunc)
     6000    0.007    0.000    0.031    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:357(compute_bounding_box)
    12000    0.008    0.000    0.029    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:41(_wrapit)
      806    0.009    0.000    0.029    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:199(clip_polygon_circle)
    19076    0.006    0.000    0.024    0.000 /Users/paolomosconi/.local/share/uv/python/cpython-3.13.3-macos-aarch64-none/lib/python3.13/typing.py:1131(_typevar_subst)
    33420    0.017    0.000    0.019    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:148(signed_distance)
    12000    0.006    0.000    0.017    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:69(_wrapreduction)
    12000    0.002    0.000    0.017    0.000 {method 'clip' of 'numpy.ndarray' objects}
    19077    0.011    0.000    0.016    0.000 /Users/paolomosconi/.local/share/uv/python/cpython-3.13.3-macos-aarch64-none/lib/python3.13/typing.py:173(_type_check)
      300    0.005    0.000    0.015    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/sweep.py:58(build_events)
    12000    0.014    0.000    0.014    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/_methods.py:98(_clip)




======================================================================
Profiling: Many AOIs (demanding workload)
  Samples: 100, AOIs: 50
======================================================================
         361887 function calls in 0.166 seconds

   Ordered by: cumulative time
   List reduced from 88 to 20 due to restriction <20>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.166    0.166 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/tracking/algorithm.py:321(compute_attention_seconds)
      100    0.002    0.000    0.166    0.002 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/tracking/algorithm.py:147(process_single_sample)
      100    0.007    0.000    0.161    0.002 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/api.py:139(find_largest_obstacle)
     5000    0.011    0.000    0.106    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:14(clip_polygon_to_wedge)
      100    0.014    0.000    0.036    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/sweep.py:393(compute_coverage)
    10000    0.004    0.000    0.033    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:2241(clip)
    10000    0.005    0.000    0.029    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:51(_wrapfunc)
     5000    0.005    0.000    0.025    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:357(compute_bounding_box)
      946    0.011    0.000    0.024    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:115(clip_polygon_halfplane)
    10000    0.007    0.000    0.024    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:41(_wrapit)
      700    0.001    0.000    0.019    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/sweep.py:208(resolve_interval)
     2100    0.015    0.000    0.015    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/sweep.py:341(_find_min_distance_at_angle)
    10000    0.002    0.000    0.014    0.000 {method 'clip' of 'numpy.ndarray' objects}
    10000    0.005    0.000    0.013    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:69(_wrapreduction)
    10000    0.012    0.000    0.012    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/_methods.py:98(_clip)
      249    0.003    0.000    0.009    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:199(clip_polygon_circle)
     5000    0.002    0.000    0.009    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:3190(min)
     5000    0.002    0.000    0.008    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:3052(max)
    10000    0.008    0.000    0.008    0.000 {method 'reduce' of 'numpy.ufunc' objects}
     4780    0.002    0.000    0.007    0.000 /Users/paolomosconi/.local/share/uv/python/cpython-3.13.3-macos-aarch64-none/lib/python3.13/typing.py:1131(_typevar_subst)




======================================================================
Profiling: Very long session (10 min)
  Samples: 600, AOIs: 10
======================================================================
         1067660 function calls in 0.547 seconds

   Ordered by: cumulative time
   List reduced from 88 to 20 due to restriction <20>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.001    0.001    0.548    0.548 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/tracking/algorithm.py:321(compute_attention_seconds)
      600    0.004    0.000    0.547    0.001 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/tracking/algorithm.py:147(process_single_sample)
      600    0.014    0.000    0.537    0.001 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/api.py:139(find_largest_obstacle)
     6000    0.019    0.000    0.314    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:14(clip_polygon_to_wedge)
      522    0.069    0.000    0.171    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/sweep.py:393(compute_coverage)
     7172    0.080    0.000    0.169    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:115(clip_polygon_halfplane)
     3498    0.007    0.000    0.089    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/sweep.py:208(resolve_interval)
    10494    0.071    0.000    0.073    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/sweep.py:341(_find_min_distance_at_angle)
     1291    0.015    0.000    0.046    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:199(clip_polygon_circle)
    33852    0.011    0.000    0.043    0.000 /Users/paolomosconi/.local/share/uv/python/cpython-3.13.3-macos-aarch64-none/lib/python3.13/typing.py:1131(_typevar_subst)
    12000    0.005    0.000    0.043    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:2241(clip)
    12000    0.006    0.000    0.037    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:51(_wrapfunc)
    60126    0.031    0.000    0.034    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:148(signed_distance)
     6000    0.007    0.000    0.033    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:357(compute_bounding_box)
    12000    0.009    0.000    0.030    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:41(_wrapit)
    33852    0.019    0.000    0.029    0.000 /Users/paolomosconi/.local/share/uv/python/cpython-3.13.3-macos-aarch64-none/lib/python3.13/typing.py:173(_type_check)
      522    0.008    0.000    0.023    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/sweep.py:58(build_events)
    23392    0.018    0.000    0.018    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/geometry.py:10(normalize_angle)
    12000    0.007    0.000    0.017    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:69(_wrapreduction)
    12000    0.003    0.000    0.017    0.000 {method 'clip' of 'numpy.ndarray' objects}




======================================================================
Profiling: Demanding workload (300 samples × 50 AOIs)
  Samples: 300, AOIs: 50
======================================================================
         1163649 function calls in 0.406 seconds

   Ordered by: cumulative time
   List reduced from 88 to 20 due to restriction <20>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.001    0.001    0.406    0.406 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/tracking/algorithm.py:321(compute_attention_seconds)
      300    0.004    0.000    0.405    0.001 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/tracking/algorithm.py:147(process_single_sample)
      300    0.015    0.000    0.395    0.001 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/api.py:139(find_largest_obstacle)
    15000    0.025    0.000    0.265    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:14(clip_polygon_to_wedge)
      300    0.035    0.000    0.085    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/sweep.py:393(compute_coverage)
    30000    0.010    0.000    0.076    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:2241(clip)
     3963    0.035    0.000    0.074    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:115(clip_polygon_halfplane)
    30000    0.010    0.000    0.067    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:51(_wrapfunc)
    15000    0.012    0.000    0.058    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:357(compute_bounding_box)
    30000    0.016    0.000    0.054    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:41(_wrapit)
     2194    0.003    0.000    0.044    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/sweep.py:208(resolve_interval)
     6582    0.035    0.000    0.036    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/sweep.py:341(_find_min_distance_at_angle)
    30000    0.005    0.000    0.031    0.000 {method 'clip' of 'numpy.ndarray' objects}
    30000    0.012    0.000    0.031    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:69(_wrapreduction)
    30000    0.027    0.000    0.027    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/_methods.py:98(_clip)
      806    0.008    0.000    0.023    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/view_arc/obstacle/clipping.py:199(clip_polygon_circle)
    15000    0.004    0.000    0.020    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:3190(min)
    19076    0.005    0.000    0.019    0.000 /Users/paolomosconi/.local/share/uv/python/cpython-3.13.3-macos-aarch64-none/lib/python3.13/typing.py:1131(_typevar_subst)
    15000    0.004    0.000    0.019    0.000 /Users/paolomosconi/Source/Repos/visionarea-data-analysis/view-direction/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:3052(max)
    30000    0.017    0.000    0.017    0.000 {method 'reduce' of 'numpy.ufunc' objects}




======================================================================
ANALYSIS SUMMARY
======================================================================

Based on the profiling output above, we can identify:

1. **Hot spots**: Which functions consume the most time?
   - Is it the sweep algorithm?
   - Is it polygon clipping?
   - Is it the coordinate transformations?

2. **Potential optimizations**:
   - Pre-filter AOIs outside max_range from viewer position
   - Cache AOI bounding boxes (computed per call)
   - Vectorize operations where possible
   - Early exit for samples clearly outside all AOI regions

3. **Trade-offs**:
   - Optimization complexity vs. performance gain
   - Memory overhead vs. speed improvement
   - Accuracy preservation vs. approximation

Next steps:
- Review the top functions by cumulative time
- Identify if any pre-computation helps
- Consider implementing minimal optimizations if bottlenecks are clear

