Search code examples
node.jsreactjsgeojsonkepler.gl

Unable to process geojson : JavaScript heap out of memory


I am trying to use kepler.gl to process a geojson file and visualize it. I have used Kepler's processes.processGeojson module in order to use the file. The file is 380Mb and processing it gives the error

JavaScript heap out of memory. [This is a run time error and occurs when I enter * npm start *

I have tried running the code as such

node --max_old_space_size=8192 node_modules/kepler.gl/*.js && npm start

to allcoate all of my laptop's RAM but, this still throws error of heap out of memory.

This is code written in React.js that causes the problem

class App extends Component {
  componentDidMount() {

    const londonData = Processors.processGeojson(london); 

    // Create dataset structure
    dispatch(addDataToMap({
      datasets: {
        info: {
          label: 'Traffic data in London',
          id: 'test_trip_data'
        },
        // use processGeojson to convert geojson to kerpler.gl struct
        data: londonData
      }
     }));
  }

Expected results: When I run the code above with a small csv file ( < 2MB) the web app runs perfectly and gets data pre loaded.

Actual results: Since the geojson I'm trying to process is 380M, I get the following errors

<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x2557c4d5be3d]
    1: StubFrame [pc: 0x2557c4d4b476]
Security context: 0x13692fb1e6e9 <JSObject>
    2: replace [0x13692fb105e9](this=0x1369fe802201 <Very long string[389761882]>,0x13699c38f8e9 <JSRegExp <String[610]: ((['"])(?:(?!\2|\\).|\\(?:\r\n|[\s\S]))*(\2)?|`(?:[^`\\$]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{[^}]*\}?)*\}?)*(`)?)|(\/\/.*)|(\/\*(?:[^*]|\*(?!\/))*(\*\/)?)|(\/(?!\*)(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\]\\]...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 0x10003d035 node::Abort() [/usr/local/bin/node]
 2: 0x10003d23f node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
 3: 0x1001b8e15 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 4: 0x100586d72 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
 5: 0x100590274 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
 6: 0x10055f576 v8::internal::Factory::NewFixedArrayWithFiller(v8::internal::Heap::RootListIndex, int, v8::internal::Object*, v8::internal::PretenureFlag) [/usr/local/bin/node]
 7: 0x10081e506 v8::internal::Runtime_RegExpExecMultiple(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
 8: 0x2557c4d5be3d 
Abort trap: 6

Any advice/help/suggestions on how I can solve this problem would be greatly appreciated.


Solution

  • run

    node --max_old_space_size=8192 app.js