I'm proposing a new structure of $wp_filter array.
This one can prevents the loops to add and to remove filters.
With this changes the follow code is exec with not relevant differences:
for($i = 0, $j = 100000; $i<$j; $i++)
add_filter("tag$i", "funtion");
But this is faster:
for($i = 0, $j = 100000; $i < $j; $i++)
for($i2 = 0, $j2 = 3; $i2 < $j2; $i2++)
add_filter("tag$i", "funtion$i2");
The core of my proposal is to change the add_filter function with this one:
function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
global $wp_filter;
$wp_filter[$tag][$priority][serialize($function_to_add)] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
return true;
}