Openanzo has a powerful RDF javascript library in the org.openanzo.js project. The library has a highly optimized quad store. A quadstore stores RDF statements that have namedGraphUri values (in addition to the standard subject, predicate and object values).

anzo.rdf.QuadStore

  
   dojo.require("anzo.rdf.QuadStore"); // reference the object

   // register namespace
   anzo.rdf.registerNamespace("ex", "http://www.example.org/"); 

   var store = new anzo.rdf.QuadStore();
   store.add("ex:subj", "ex:pred", "dog", "ex:graph1");
   store.isEmpty(); // returns false
   store.size(); // returns 1
   store.find("ex:subj"); // returns an array with a single statement in it
We can use anzo.rdf.NamedGraphs as proxies to the quadstore. Once a NamedGraph has been created with the store, all statements are stored in the underlying quadstore. In this way the NamedGraph becomes a convenient way to add triples to a graph which then get passed to the quadstore as quads (with the name of the graph being the fourth value in the statement).
  
  var store = new anzo.rdf.QuadStore();
  
  var graph1 = new anzo.rdf.NamedGraph("ex:graph1", store);
  graph1.add("http://www.example.org/subj1", "ex:pred1", "dog");
   
  var graph2 = new anzo.rdf.NamedGraph("ex:graph2", store);
  graph2.add("ex:subj2", "ex:pred2", "cat");

  graph1.contains(null, null, "dog");  // true
  graph2.contains(null, null, "cat");  // true
  store.contains(null, null, "dog");    // true
  store.contains(null, null, "cat");    // true
Performance Numbers
In this test I loaded up the quadstore with 100,000 quads. I then ran a number of timed calls to the find method with a pattern from the first of the 100,000 statements that were added, a pattern from the middle of that set and a pattern from the very end. Then, I added an additional 100 quads and timed that. I then removed those 100 and timed that. Here are my results:
  
----------------------------------------------
added: 100000 statements to the store
----------------------------------------------
find(s, p, o, c)
Elapsed time calling find (s, p, o, c) on first added statement pattern: 0 milliseconds. Num stmts found: 0
Elapsed time calling find (s, p, o, c) on middle added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 0
Elapsed time calling find (s, p, o, c) on last added statement pattern: 0 milliseconds. Num stmts found: 0
----------------------------------------------
find(?, p, o, c)
Elapsed time calling find (?, p, o, c) on first added statement pattern: 0 milliseconds. Num stmts found: 1
Elapsed time calling find (?, p, o, c) on middle added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 1
Elapsed time calling find (?, p, o, c) on last added statement pattern: 0 milliseconds. Num stmts found: 1
----------------------------------------------
find(s, ?, o, c)
Elapsed time calling find (s, ?, o, c) on first added statement pattern: 0 milliseconds. Num stmts found: 1
Elapsed time calling find (s, ?, o, c) on middle added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 1
Elapsed time calling find (s, ?, o, c) on last added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 1
----------------------------------------------
find(s, p, ?, c)
Elapsed time calling find (s, p, ?, c) on first added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 100
Elapsed time calling find (s, p, ?, c) on middle added statement pattern: 0.6666666666666666 milliseconds. Num stmts found: 100
Elapsed time calling find (s, p, ?, c) on last added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 100
----------------------------------------------
find(s, p, o, ?)
Elapsed time calling find (s, p, o, ?) on first added statement pattern: 0 milliseconds. Num stmts found: 1
Elapsed time calling find (s, p, o, ?) on middle added statement pattern: 0 milliseconds. Num stmts found: 1
Elapsed time calling find (s, p, o, ?) on last added statement pattern: 0 milliseconds. Num stmts found: 1
----------------------------------------------
find(?, ?, o, c)
Elapsed time calling find (?, ?, o, c) on first added statement pattern: 0 milliseconds. Num stmts found: 1
Elapsed time calling find (?, ?, o, c) on middle added statement pattern: 0 milliseconds. Num stmts found: 1
Elapsed time calling find (?, ?, o, c) on last added statement pattern: 0 milliseconds. Num stmts found: 1
----------------------------------------------
find(s, ?, ?, c)
Elapsed time calling find (s, ?, ?, c) on first added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 100
Elapsed time calling find (s, ?, ?, c) on middle added statement pattern: 0.6666666666666666 milliseconds. Num stmts found: 100
Elapsed time calling find (s, ?, ?, c) on last added statement pattern: 0.6666666666666666 milliseconds. Num stmts found: 100
----------------------------------------------
find(s, p, ?, ?)
Elapsed time calling find (s, p, ?, ?) on first added statement pattern: 0 milliseconds. Num stmts found: 100
Elapsed time calling find (s, p, ?, ?) on middle added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 100
Elapsed time calling find (s, p, ?, ?) on last added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 100
----------------------------------------------
find(?, p, ?, c)
Elapsed time calling find (?, p, ?, c) on first added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 100
Elapsed time calling find (?, p, ?, c) on middle added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 100
Elapsed time calling find (?, p, ?, c) on last added statement pattern: 0.6666666666666666 milliseconds. Num stmts found: 100
----------------------------------------------
find(s, ?, o, ?)
Elapsed time calling find (s, ?, o, ?) on first added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 1
Elapsed time calling find (s, ?, o, ?) on middle added statement pattern: 0 milliseconds. Num stmts found: 1
Elapsed time calling find (s, ?, o, ?) on last added statement pattern: 0 milliseconds. Num stmts found: 1
----------------------------------------------
find(?, p, o, ?)
Elapsed time calling find (?, p, o, ?) on first added statement pattern: 0 milliseconds. Num stmts found: 1
Elapsed time calling find (?, p, o, ?) on middle added statement pattern: 0 milliseconds. Num stmts found: 1
Elapsed time calling find (?, p, o, ?) on last added statement pattern: 0 milliseconds. Num stmts found: 1
----------------------------------------------
find(?, ?, ?, c)
Elapsed time calling find (?, ?, ?, c) on first added statement pattern: 7 milliseconds. Num stmts found: 1000
Elapsed time calling find (?, ?, ?, c) on middle added statement pattern: 7.333333333333333 milliseconds. Num stmts found: 1000
Elapsed time calling find (?, ?, ?, c) on last added statement pattern: 8 milliseconds. Num stmts found: 1000
----------------------------------------------
find(?, ?, o, ?)
Elapsed time calling find (?, ?, o, ?) on first added statement pattern: 0 milliseconds. Num stmts found: 1
Elapsed time calling find (?, ?, o, ?) on middle added statement pattern: 0 milliseconds. Num stmts found: 1
Elapsed time calling find (?, ?, o, ?) on last added statement pattern: 0 milliseconds. Num stmts found: 1
----------------------------------------------
find(?, p, ?, ?)
Elapsed time calling find (?, p, ?, ?) on first added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 100
Elapsed time calling find (?, p, ?, ?) on middle added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 100
Elapsed time calling find (?, p, ?, ?) on last added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 100
----------------------------------------------
find(s, ?, ?, ?)
Elapsed time calling find (s, ?, ?, ?) on first added statement pattern: 0 milliseconds. Num stmts found: 100
Elapsed time calling find (s, ?, ?, ?) on middle added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 100
Elapsed time calling find (s, ?, ?, ?) on last added statement pattern: 0.3333333333333333 milliseconds. Num stmts found: 100
----------------------------------------------
find(?, ?, ?, ?)
Elapsed time calling find (?, ?, ?, ?): 350 milliseconds. Num stmts found: 100000
----------------------------------------------
adding num stmts: 100
Elapsed time adding statements: 11.333333333333334 milliseconds.
----------------------------------------------
removing num stmts: 100
Elapsed time removing statements: 0 milliseconds.