When programmatically adding views, what is a more efficient way to add them other than include them in mymodule.views_default.inc? I have written a module that writes views programmatically, and my mymodule.views_default.inc file is enormous. Currently there are 150 individual views, and 780 will be the target.

But, even with the test group of 150 several things are happening.

1) when enabling the module via drush, php memory usage goes through the roof. It climbs into the gigs (TOP command), but it finally loads.

2) but, when I then try to view the site I get WSOD, and the top command shows apache2 climbs into the gigs for memory usage until the Apache process actually crashes.  Of course there is not enough memory to load it, and it's of course unrealistic to put php memory limit in the gigs.

What's going on here? How is the code in mymodule.views_default.inc actually handled once it's loaded? Where is it being loaded to? Is it loaded into memory for each Apache process? If I can actually get it loaded will my Apache process footprints actually shrink back down to something normal?

Can this file be divided up into individual files, and would this even help? Is it better to someway put them into the database instead of using the file at all?

In other words, how can I get almost 1000 views loaded and continue doing business as usual?

note, if you are curious, this is a census data project. I don't want to use filters or arguments as each set of data needs to to have its own individual page URL and other criteria unique to that data set.
I'm not 100% sure if it'd help performance-wise, but it is possible to separate the Views into different files. In your case, this is probably useful anyway as that's a LOT of Views.

If you create a folder in your module called "views" (or whatever you want), then you can just add the following to your implementation of hook_views_default_views.

function MYMODULE_views_default_views() {
  $files = file_scan_directory(drupal_get_path('module', 'MYMODULE'). '/views', '/.view/');
  foreach ($files as $filepath =&gt; $file) {
    require $filepath;
    if (isset($view)) {
      $views[$view-&gt;name] = $view;
    }
  }
  return $views;
}


DISCLAIMER/CREDIT:

This code was taken from this blog post, and this comment, so make sure you pop over there and say thank you :)