damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 99b5dc94cbec6d01f483d380eefa8882265f1e51
parent e34351ca37b89b5ba9d0a011076aee555dbbfcf0
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 23 Jul 2023 12:08:46 -0700

ndb: copy over perf improvements

Diffstat:
Mnostrdb/Test/NdbTests.swift | 10+++++-----
Mnostrdb/nostrdb.c | 13++++++++-----
2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/nostrdb/Test/NdbTests.swift b/nostrdb/Test/NdbTests.swift @@ -28,7 +28,7 @@ final class NdbTests: XCTestCase { XCTAssertEqual(hex_encode(note.id), id) XCTAssertEqual(hex_encode(note.pubkey), pubkey) - XCTAssertEqual(note.count, 34058) + XCTAssertEqual(note.count, 34322) XCTAssertEqual(note.kind, 3) XCTAssertEqual(note.created_at, 1689904312) @@ -82,19 +82,19 @@ final class NdbTests: XCTestCase { } var count = 0 + var char_count = 0 for tag in note.tags() { for elem in tag { print("iter_elem \(elem.string())") - /* - for _ in elem { - count += 1 + for c in elem { + char_count += 1 } - */ } count += 1 } XCTAssertEqual(count, 786) + XCTAssertEqual(char_count, 24370) } } diff --git a/nostrdb/nostrdb.c b/nostrdb/nostrdb.c @@ -136,7 +136,7 @@ static inline int ndb_builder_find_str(struct ndb_builder *builder, uint32_t index = ((uint32_t*)builder->str_indices.start)[i]; const char *some_str = (const char*)builder->strings.start + index; - if (!strncmp(some_str, str, len)) { + if (!memcmp(some_str, str, len)) { // found an existing matching str, use that index *pstr = ndb_offset_str(index); return 1; @@ -171,10 +171,13 @@ static int ndb_builder_push_packed_id(struct ndb_builder *builder, unsigned char *id, union ndb_packed_str *pstr) { - if (ndb_builder_find_str(builder, (const char*)id, 32, pstr)) { - pstr->packed.flag = NDB_PACKED_ID; - return 1; - } + // Don't both find id duplicates. very rarely are they duplicated + // and it slows things down quite a bit. If we really care about this + // We can switch to a hash table. + //if (ndb_builder_find_str(builder, (const char*)id, 32, pstr)) { + // pstr->packed.flag = NDB_PACKED_ID; + // return 1; + //} if (ndb_builder_push_str(builder, (const char*)id, 32, pstr)) { pstr->packed.flag = NDB_PACKED_ID;