4 Answers
4

Why don't you do this in chunks.I mean schedule you cron using elysia_cron or ultimate cron at every hour or something and export chunks of users at a time,flag users you exported and at every next cron run get the new ones.

One important thing you should have crontab set on your server,do not use drupal's default poormanscron.

In Drupal 8, you can use Default Content module to export users into CSV file via drush command which can be invoked periodically by adding into the system's crontab. It's better to approach, as having big chunk of data exports in hook_cron, as it's blocking the other important processing.

Another way is to create a View which exports users in CSV format by using Views Datasource module. Then you can enable caching, so the results are cached.

As the suggestion, to avoid using too many resources on processing and memory (such as a huge number of calls to user_load), you should implement memory caching service such as Redis or Memcached. Further more, please check: How do you improve Drupal performance?

If you still got the issue, use PHP profiler (such as XDebug) to find the cause of your issue.