How to use pager or term limit for taxonomy_get_tree($vid)? How to use pager or how to limit terms, when using taxonomy_get_tree($vid)?

I have this code for terms generation:

&lt;?php
$vid = 2;
$terms = taxonomy_get_tree($vid);   
$max_depth = (!isset($max_depth)) ? count($children[$vid]) : $max_depth;

foreach ($terms as $term) {
if ($term-&gt;depth == 0) 
{  
print "" .l("&lt;b&gt;Auto Insurance for &amp;nbsp;&lt;/b&gt; " .$term-&gt;name,'taxonomy/term/'.$term-&gt;tid, array('attributes' =&gt; array('title' =&gt; $term-&gt;name, ), 'html' =&gt; TRUE) ). "";

}}

?&gt;


But there are thousands of terms or sub terms. Some pages are then loading more then 20 seconds. I need to improve this situation.

Can you advice me please? Do you know some solution? Pager, Jquery, Ajax?
Add a counter into your for each statement that counts the array index and terminates after X number of items.  That'd fix it.