Grouping a large number of entries
First, based on your example code I don't think you actually need to loop on the entries – you could simply group them on the brand name, and then loop on the keys for the grouped array (the keys would be your brand names):

{% set brands = allEntries|group('brand')|keys %}

{% for brand in brands %}
     &lt;option value="{{ brand }}"&gt;{{ brand }}&lt;/option&gt;
{% endfor %}


So that's a slight optimization, but you'd still be pulling ~18k entries to print ~140 brand names and I'm not sure the above wouldn't still crash your server – so ideally you should probably use a different strategy altogether.

If you're comfortable w/ writing a little PHP, I'd suggest you scaffold a custom plugin – make sure that the Variables component is included, and add something like the below to the variables/YourPluginHandleVariable.php class:

public function getBrands()
{
    $query = craft()-&gt;db-&gt;createCommand();
    $query-&gt;selectDistinct('field_brand');
    $query-&gt;from('content');
    return array_filter($query-&gt;queryColumn());
}


In your template, you'd use this like so:

{% set brands = craft.yourPluginHandle.getBrands() %}

{% for brand in brands %}
     &lt;option value="{{ brand }}"&gt;{{ brand }}&lt;/option&gt;
{% endfor %}


Be sure to replace yourPluginHandle and YourPluginHandleVariable with the actual handle for your plugin.

Note that I haven't actually tested the above w/ as many as +18k rows, so even a distinct select query might not be performant enough. Of course, you can always cache the result.