With large numbers of referenceable nodes (eg > 25000 in my case), adding a filter on a reference field causes a php timeout.

Offending code is the call to _node_reference_potential_references_standard in line 804 of node_reference.module.

If you remove the check_plain in line 883, this doesn't timeout for me. I'm not sure why it would be necessary for a views filter to have the html chars encoded either, so maybe in the case of a view filter the call should add an option in the second argument that turns it off. Thus:

line 804:
$options['skipcheckplain'] = TRUE;

line 883:

);
if($options['skipcheckplain'])
{
  $references[$node->nid]['rendered'] = $node->title;
}
else
{
  $references[$node->nid]['rendered'] = check_plain($node->title);
}

I don't know what else calls node_reference_potential_references in what context, though.

Thoughts?