diff options
-rw-r--r-- | Changelog | 4 | ||||
-rw-r--r-- | node/ejdb_native.cc | 17 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | tcejdb/bson.c | 8 | ||||
-rw-r--r-- | tcejdb/bson.h | 1 | ||||
-rwxr-xr-x | tcejdb/configure | 18 | ||||
-rw-r--r-- | tcejdb/configure.ac | 2 |
7 files changed, 41 insertions, 11 deletions
@@ -1,3 +1,7 @@ +2012-12-25 Anton Adamansky. <adamansky@gmail.com> + * Nodejs database cursors more GC friendly + - Release 1.0.34 + 2012-12-24 Anton Adamansky. <adamansky@gmail.com> * Better array query matching * $elemMatch support in queries (ticket: #13) diff --git a/node/ejdb_native.cc b/node/ejdb_native.cc index 576f2a0..8cc2129 100644 --- a/node/ejdb_native.cc +++ b/node/ejdb_native.cc @@ -14,6 +14,7 @@ #include <sstream> #include <locale.h> #include <ext/hash_set> +#include <stdint.h> using namespace node; using namespace v8; @@ -1404,6 +1405,8 @@ finish: static Persistent<FunctionTemplate> constructor_template; NodeEJDB *m_nejdb; + intptr_t m_mem; //amount of memory contained in cursor + TCLIST *m_rs; //result set bsons int m_pos; //current cursor position bool m_no_next; //no next() was called @@ -1555,15 +1558,29 @@ finish: tclistdel(m_rs); m_rs = NULL; } + V8::AdjustAmountOfExternalAllocatedMemory(-m_mem + sizeof(NodeEJDBCursor)); } NodeEJDBCursor(NodeEJDB *_nejedb, TCLIST *_rs) : m_nejdb(_nejedb), m_rs(_rs), m_pos(0), m_no_next(true) { assert(m_nejdb); this->m_nejdb->Ref(); + m_mem = sizeof (NodeEJDBCursor); + if (m_rs) { + intptr_t cmem = 0; + int i = 0; + for (; i < TCLISTNUM(m_rs) && i < 1000; ++i) { //Max 1K iterations + cmem += bson_size2(TCLISTVALPTR(m_rs, i)); + } + if (i > 0) { + m_mem += (intptr_t) (((double) cmem / i) * TCLISTNUM(m_rs)); + } + V8::AdjustAmountOfExternalAllocatedMemory(m_mem); + } } virtual ~NodeEJDBCursor() { close(); + V8::AdjustAmountOfExternalAllocatedMemory(-sizeof(NodeEJDBCursor)); } public: diff --git a/package.json b/package.json index 4ad2647..5dad40b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "ejdb", - "version" : "1.0.33", + "version" : "1.0.34", "main" : "node/ejdb.js", "homepage" : "http://ejdb.org", "description" : "EJDB - Embedded JSON Database engine", diff --git a/tcejdb/bson.c b/tcejdb/bson.c index 44e34d4..3b1f637 100644 --- a/tcejdb/bson.c +++ b/tcejdb/bson.c @@ -115,6 +115,14 @@ EJDB_EXPORT int bson_size(const bson *b) { return i; } +EJDB_EXPORT int bson_size2(const void *bsdata) { + int i; + if (!bsdata) + return 0; + bson_little_endian32(&i, bsdata); + return i; +} + EJDB_EXPORT int bson_buffer_size(const bson *b) { return (b->cur - b->data + 1); } diff --git a/tcejdb/bson.h b/tcejdb/bson.h index 5424974..726ac25 100644 --- a/tcejdb/bson.h +++ b/tcejdb/bson.h @@ -143,6 +143,7 @@ EJDB_EXPORT void bson_dispose(bson* b); * @return the size. */ EJDB_EXPORT int bson_size(const bson *b); +EJDB_EXPORT int bson_size2(const void *bsdata); EJDB_EXPORT int bson_buffer_size(const bson *b); /** diff --git a/tcejdb/configure b/tcejdb/configure index 1b72686..fbc5a5b 100755 --- a/tcejdb/configure +++ b/tcejdb/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for tcejdb 1.0.33. +# Generated by GNU Autoconf 2.69 for tcejdb 1.0.34. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -577,8 +577,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='tcejdb' PACKAGE_TARNAME='tcejdb' -PACKAGE_VERSION='1.0.33' -PACKAGE_STRING='tcejdb 1.0.33' +PACKAGE_VERSION='1.0.34' +PACKAGE_STRING='tcejdb 1.0.34' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1257,7 +1257,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures tcejdb 1.0.33 to adapt to many kinds of systems. +\`configure' configures tcejdb 1.0.34 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1318,7 +1318,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of tcejdb 1.0.33:";; + short | recursive ) echo "Configuration of tcejdb 1.0.34:";; esac cat <<\_ACEOF @@ -1424,7 +1424,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -tcejdb configure 1.0.33 +tcejdb configure 1.0.34 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1722,7 +1722,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by tcejdb $as_me 1.0.33, which was +It was created by tcejdb $as_me 1.0.34, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -4870,7 +4870,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by tcejdb $as_me 1.0.33, which was +This file was extended by tcejdb $as_me 1.0.34, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -4923,7 +4923,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -tcejdb config.status 1.0.33 +tcejdb config.status 1.0.34 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/tcejdb/configure.ac b/tcejdb/configure.ac index 5de2430..7e25966 100644 --- a/tcejdb/configure.ac +++ b/tcejdb/configure.ac @@ -11,7 +11,7 @@ test -n "$CPPFLAGS" && MYCPPFLAGS="$CPPFLAGS $MYCPPFLAGS" test -n "$LDFLAGS" && MYLDFLAGS="$LDFLAGS $MYLDFLAGS" # Package name -AC_INIT(tcejdb, 1.0.33) +AC_INIT(tcejdb, 1.0.34) # Package information MYLIBVER=9 |