Skip to content

C2MIR high memory usage when executing sqlite3  #411

@mingodad

Description

@mingodad

Testing c2mir with sqlite3 after minor fixes (see bellow) I'm getting this results:

  • sqlite3 native : 4.6 MB
  • sqlite3 c2mir : 584 MB

Native sqlite3:

echo 'select 2 as two;' | /usr/bin/time sqlite3
2
0.00user 0.00system 0:00.00elapsed 100%CPU (0avgtext+0avgdata 4588maxresident)k
0inputs+0outputs (0major+196minor)pagefaults 0swaps

c2mir sqlite3:

echo 'select 2 as two;' | sh run-sqlite3.sh
sqlite3.c:35613:19: warning -- number 1e10000f is out of range -- using IEEE infinity
shell.c:21754:37: warning -- number 1e10000f is out of range -- using IEEE infinity
2
2.44user 0.31system 0:02.75elapsed 99%CPU (0avgtext+0avgdata 584216maxresident)k
0inputs+0outputs (0major+171348minor)pagefaults 0swaps

run-sqlite3.sh:

#!/bin/sh
#need remove this cast { (u8*)" " }; and coment "atexit" in shell.c
sqliteh=.
/usr/bin/time ./c2m  \
	-DSQLITE_OS_UNIX=1 \
	-DBUILD_sqlite \
	-DNDEBUG \
	-DSQLITE_THREADSAFE=0 \
	-DSQLITE_ENABLE_MATH_FUNCTIONS \
	-DSQLITE_ENABLE_COLUMN_METADATA=1 \
	-DSQLITE_ENABLE_FTS4 \
	-DSQLITE_ENABLE_RTREE \
	-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
	-DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION \
	-DSQLITE_ENABLE_STMTVTAB \
	-DSQLITE_ENABLE_DBPAGE_VTAB \
	-DSQLITE_ENABLE_DBSTAT_VTAB \
	-DSQLITE_ENABLE_BYTECODE_VTAB \
	-DSQLITE_ENABLE_OFFSET_SQL_FUNC \
	-D_FILE_OFFSET_BITS \
	-O2 -I$sqliteh $sqliteh/sqlite3.c $sqliteh/shell.c \
	 -ei

Fixes for sqlite3.c:

--- <unnamed>
+++ <unnamed>
@@ -130362,7 +130362,7 @@
   assert( zIn==sqlite3_value_text(argv[0]) );
   if( argc==1 ){
     static const unsigned lenOne[] = { 1 };
-    static unsigned char * const azOne[] = { (u8*)" " };
+    static unsigned char * const azOne[] = { /*(u8*)*/" " };
     nChar = 1;
     aLen = (unsigned*)lenOne;
     azChar = (unsigned char **)azOne;

Fixes for shell.c:

--- <unnamed>
+++ <unnamed>
@@ -30467,9 +30467,9 @@
   consStreams = consoleClassifySetup(stdin, stdout, stderr);
   stdin_is_interactive = (consStreams & SAC_InConsole)!=0;
   stdout_is_console = (consStreams & SAC_OutConsole)!=0;
-  atexit(consoleRestore);
+  //atexit(consoleRestore);
 #endif
-  atexit(sayAbnormalExit);
+  //atexit(sayAbnormalExit);
 #ifdef SQLITE_DEBUG
   mem_main_enter = sqlite3_memory_used();
 #endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions