LoginSignup
0
0

More than 5 years have passed since last update.

Promiseの闇?(再帰の闇かもしれない)

Last updated at Posted at 2016-10-13

200万行近いShapefileがあるじゃろ?

Node.jsで処理しようと思えば、Shapefile モジュールを使うじゃろ?

で、単純に、サンプルに等しい処理をまわすと...

shapefile単純ぶんまわし
var shapefile = require("shapefile");

var count = 0;   
shapefile.open("example.shp")
    .then(source => source.read()
    .then(function log(result) {
      if (result.done) return;
      count = count + 1;
      if (count % 10000 == 0) console.log(count); 
      return source.read().then(log);
    }))
  .catch(error => console.error(error.stack));

160万行目くらいで、こうじゃ!

Windowsコマンドプロンプト
<--- Last few GCs --->

 1775279 ms: Scavenge 1398.3 (1458.1) -> 1398.3 (1458.1) MB, 0.3 / 0 ms (+ 0.0 m
s in 1 steps since last GC) [allocation failure] [incremental marking delaying m
ark-sweep].
 1776507 ms: Mark-sweep 1398.3 (1458.1) -> 1398.3 (1458.1) MB, 1227.5 / 0 ms (+
0.0 ms in 2 steps since start of marking, biggest step 0.0 ms) [last resort gc].

 1777674 ms: Mark-sweep 1398.3 (1458.1) -> 1398.3 (1458.1) MB, 1178.9 / 0 ms [la
st resort gc].


<--- JS stacktrace --->

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

Security context: 00000114947E3AD1 <JS Object>
    2: decode [D:\Works\XXXXXX XXX\XXXX\node_modules\text-encoding\lib\encoding.
js:1128] [pc=00000318CB0F1257] (this=0000024543C241C9 <a TextDecoder with map 00
0001CBC3223059>,input=0000015E2DF8DE69 <an Uint8Array with map 0000035139609CC9>
,options=0000015E2DF8DE31 <an Object with map 00000351396095E9>)
    3: arguments adaptor frame: 1->2
    7: _decode [native v8natives.js:1213] [pc=0000031...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

これ以上は知識なさ過ぎて、Promiseネストか再帰ネストかどっちが問題なんかようわからへんけど、160万階層もネストすればまあ何かしら問題あるんやろなあ...

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0