Optimize performance of custom pre-built option list to webform I am looking to add a pre-built options list, based on a query. I crafted the function nicely with the below code

function mitacan_webform_select_options_info() {
    $items = [];
    if (function_exists('basliklariAl')) {
        $items['addresses'] = array(
            'title' =&gt; 'Stok Kodları',
            'options callback' =&gt; 'basliklariAl'
        );
    }
    return $items;
}

function basliklariAl($component, $flat, $arguments) {
    $nodes = [];
    $select = db_select('node','n')
        -&gt;fields('n',[
            'nid',
            'title'
        ])
        -&gt;condition('type','urun')
        -&gt;execute()
        -&gt;fetchAll();
    foreach($select as $n) {
        $nodes[$n-&gt;nid] = $n-&gt;title;
    }
    return $nodes;
}


This is very slow, mostly because there are about 10k records. What can I do to optimise the process?
You can always cache the results as seen in the official documentation

  if ($cache = cache_get('my_module_cache') &amp;&amp; REQUEST_TIME &lt; $cache-&gt;expire) {
    $data = $cache-&gt;data;
  }
  else {
    $data = 'xxxxxxx'; //do all your time taking complex calculations here
    cache_set('my_module_cache', $data, 'cache',  REQUEST_TIME  + (3600 * 24 * 30 * 6)); //stores in cache table and expires after 6 months
  }


More about cache_set and cache_get