2 Commits f107c3dcf3 ... e8ab4e9767

Author SHA1 Message Date
  Stefano Cossu e8ab4e9767 Some adjustments: 1 year ago
  Stefano Cossu 2fe6a6338f Add memory profiling tests. 1 year ago

+ 3 - 3
Makefile

@@ -151,7 +151,7 @@ install: lib ## Install library and dependencies to $PREFIX. May require sudo.
 	mkdir -p $(DESTDIR)$(libdir)
 	mkdir -p $(DESTDIR)$(includedir)
 	cp liblsuprdf.a liblsuprdf.so $(DESTDIR)$(libdir) && \
-		cp include/*.h $(EXT_H) $(DESTDIR)$(includedir)
+		cp -r include/*.h include/codec $(EXT_H) $(DESTDIR)$(includedir)
 
 
 debug_install: install debug ## Install standard and debug libraries.
@@ -170,8 +170,8 @@ clean:
 
 .PHONY: deepclean ## Clean up external libraries.
 deepclean: clean
-	cd $(MDB_DIR); make clean
-	cd $(XXHASH_DIR); make clean
+	make -C $(MDB_DIR) clean
+	make -C $(XXHASH_DIR) clean
 
 
 .PHONY: uninstall ## Uninstall library (not the dependencies).

+ 0 - 77
cpython/py_graph.h

@@ -243,36 +243,6 @@ Graph_copy_contents (GraphObject *self, GraphObject *dest)
 };
 
 
-#if 0
-static PyObject *
-Graph_store (PyObject *self)
-{
-    GraphObject *dest_obj = (GraphObject *) Py_TYPE (self)->tp_alloc(
-            Py_TYPE (self), 0);
-    if (!dest_obj) return PyErr_NoMemory();
-
-    // TODO Make store ID, nsm and initial size accessible.
-    LSUP_Graph *dest = LSUP_graph_new (
-            uri, LSUP_STORE_HTABLE, NULL, NULL, 0);
-    if (!dest) {
-        PyErr_SetString (PyExc_ValueError, "Could not create graph.");
-        return -1;
-    }
-
-    LSUP_rc rc = LSUP_GraphStore (
-            ((GraphObject *) self)->ob_struct, &((dest_obj)->ob_struct), NULL);
-    if (rc != LSUP_OK) {
-        log_error (LSUP_strerror (rc));
-        PyErr_SetString (PyExc_SystemError, "Error storing graph.");
-        return NULL;
-    };
-
-    Py_INCREF (dest_obj);
-    return (PyObject *)dest_obj;
-}
-#endif
-
-
 static PyObject *
 Graph_new_from_rdf (PyTypeObject *cls, PyObject *args)
 {
@@ -365,40 +335,6 @@ inline static int build_trp_pattern (PyObject *args, LSUP_Term *spo[])
 }
 
 
-/*
-static PyObject *
-Graph_new_set_from_store_lookup (PyTypeObject *cls, PyObject *args)
-{
-    LSUP_Term *spo[3];
-
-    if (UNLIKELY ((build_trp_pattern (args, spo)) < 0)) return NULL;
-
-    LSUP_Graph **gr_a = LSUP_graph_new_lookup (spo[0], spo[1], spo[2]);
-    if (UNLIKELY (!gr_a)) {
-        // TODO implement LSUP_strerror for more details.
-        PyErr_SetString (PyExc_SystemError, "Error looking up triples.");
-        return NULL;
-    }
-
-    PyObject *ret = PySet_New (NULL);
-
-    size_t i;
-    for (i = 0; gr_a[i] != NULL; i++) {
-        PyObject *gr_obj = cls->tp_alloc(cls, 0);
-        if (!gr_obj) return NULL;
-        ((GraphObject *) gr_obj)->ob_struct = gr_a[i];
-
-        Py_INCREF (gr_obj);
-        PySet_Add (ret, gr_obj);
-    }
-    log_debug ("Found %lu graphs for pattern.", i + 1);
-
-    Py_INCREF (ret);
-    return ret;
-}
-*/
-
-
 static PyObject *
 Graph_richcmp (PyObject *self, PyObject *other, int op)
 {
@@ -593,19 +529,6 @@ static PyMethodDef Graph_methods[] = {
         METH_CLASS | METH_VARARGS,
         "Create a graph from a RDF file."
     },
-    /*
-    {
-        "from_lookup", (PyCFunction) Graph_new_set_from_store_lookup,
-        METH_CLASS | METH_VARARGS,
-        "Create a set of graphs from a store SPO lookup."
-    },
-    */
-    /*
-    {
-        "store", (PyCFunction) Graph_store, METH_NOARGS,
-        "Store a graph into the permanent back end."
-    },
-    */
     {"add", (PyCFunction) Graph_add, METH_O, "Add triples to a graph."},
     {
         "remove", (PyCFunction) Graph_remove, METH_VARARGS,

+ 43 - 0
cpython/py_term.h

@@ -299,6 +299,47 @@ static PyGetSetDef BNode_getsetters[] = {
 };
 
 
+static PyObject *
+Term_repr (TermObject *term_obj)
+{
+    LSUP_Term *term = term_obj->ob_struct;
+    char *term_repr_ptn = "<%s @%p> '%s'";
+    char *term_nt;
+    if (UNLIKELY (nt_codec.encode_term (term, NULL, &term_nt) != LSUP_OK)) {
+        PyErr_SetString (PyExc_ValueError, "Error serializing term.");
+        return NULL;
+    }
+    char *term_repr = malloc (
+            strlen (term_repr_ptn) +
+            strlen (term_nt) +
+            strlen (term_obj->tp_name) + 32); // 32 for pointer address + NUL
+    if (UNLIKELY (!term_repr)) return PyErr_NoMemory;
+    sprintf (
+            term_repr, term_repr_ptn,
+            term_obj->tp_name, term->obj, term_nt);
+
+    PyObject *result = PyUnicode_FromString (term_repr);
+    free (term_repr);
+    if (UNLIKELY (!result)) return PyErr_NoMemory;
+
+    Py_INCREF (result);
+    return result;
+}
+
+
+static PyObject *
+Term_str (PyObject *term_obj)
+{
+    LSUP_Term *term = term_obj->ob_struct;
+
+    PyObject *result = PyUnicode_FromString (term->data);
+    if (UNLIKELY (!result)) return PyErr_NoMemory;
+
+    Py_INCREF (result);
+    return result;
+}
+
+
 static PyObject *
 Term_richcmp (PyObject *obj1, PyObject *obj2, int op);
 
@@ -318,6 +359,8 @@ PyTypeObject TermType = {
     .tp_new = PyType_GenericNew,
     .tp_init = (initproc) Term_init,
     .tp_dealloc = (destructor) Term_dealloc,
+    .tp_repr = Term_repr,
+    .tp_str = Term_str,
     .tp_getset = Term_getsetters,
     .tp_richcompare = Term_richcmp,
     .tp_hash = Term_hash,

+ 32 - 0
docs/dev/NOTES.md

@@ -0,0 +1,32 @@
+# Performance test data
+
+VMWare running ArchLinux on MacBook Pro, 4-core Intel(R) Core(TM) i7-1068NG7
+CPU @ 2.30GHz, 8Gb RAM, SSD
+
+Decode
+LoC Children's Subjects SKOS/RDF
+[NT](https://id.loc.gov/download/authorities/childrensSubjects.skosrdf.nt.gz)
+and
+[TTL](https://id.loc.gov/download/authorities/childrensSubjects.skosrdf.ttl.gz)
+(379,163 triples):
+
+NT format: 19s
+TTL format: 25s
+
+Decode LoC Subject Headings (10,116,071 triples)
+
+NT: 8'33"
+TTL: 11'4"
+
+TTL takes 29%-31% longer than NT.
+
+Script (replace `<file path>` and `<format>` accordingly):
+
+```
+from lsup_rdf import env_init
+from lsup_rdf.graph import Graph
+
+env_init()
+with open("<file path>") as fh:
+    gr = Graph.from_rdf(fh, "<format>")
+```

BIN
docs/massif_decode_loc_childrensSubjects_skos_nt.png


BIN
docs/massif_decode_loc_childrensSubjects_skos_ttl.png


BIN
docs/massif_decode_loc_subjects_skos_nt.png


BIN
docs/massif_decode_loc_subjects_skos_ttl.png


+ 1 - 1
include/core.h

@@ -293,7 +293,7 @@ inline int utf8_encode (const uint32_t utf, unsigned char *out)
  */
 #define LOG_RC(rc) do {                                             \
     if ((rc) < 0) log_error (LSUP_strerror (rc));                   \
-    else if ((rc) > 0) log_warn (LSUP_strerror (rc));               \
+    else if ((rc) > 0) log_debug (LSUP_strerror (rc));               \
 } while (0);
 
 /// Error handling via goto.