Optimize search_task to reduce memory footprint