1
0
mirror of git://jb55.com/damus synced 2024-10-04 19:00:42 +00:00

ndb: copy over perf improvements

This commit is contained in:
William Casarin 2023-07-23 12:08:46 -07:00
parent e34351ca37
commit 99b5dc94cb
2 changed files with 13 additions and 10 deletions

View File

@ -28,7 +28,7 @@ final class NdbTests: XCTestCase {
XCTAssertEqual(hex_encode(note.id), id) XCTAssertEqual(hex_encode(note.id), id)
XCTAssertEqual(hex_encode(note.pubkey), pubkey) XCTAssertEqual(hex_encode(note.pubkey), pubkey)
XCTAssertEqual(note.count, 34058) XCTAssertEqual(note.count, 34322)
XCTAssertEqual(note.kind, 3) XCTAssertEqual(note.kind, 3)
XCTAssertEqual(note.created_at, 1689904312) XCTAssertEqual(note.created_at, 1689904312)
@ -82,19 +82,19 @@ final class NdbTests: XCTestCase {
} }
var count = 0 var count = 0
var char_count = 0
for tag in note.tags() { for tag in note.tags() {
for elem in tag { for elem in tag {
print("iter_elem \(elem.string())") print("iter_elem \(elem.string())")
/* for c in elem {
for _ in elem { char_count += 1
count += 1
} }
*/
} }
count += 1 count += 1
} }
XCTAssertEqual(count, 786) XCTAssertEqual(count, 786)
XCTAssertEqual(char_count, 24370)
} }
} }

View File

@ -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]; uint32_t index = ((uint32_t*)builder->str_indices.start)[i];
const char *some_str = (const char*)builder->strings.start + index; 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 // found an existing matching str, use that index
*pstr = ndb_offset_str(index); *pstr = ndb_offset_str(index);
return 1; return 1;
@ -171,10 +171,13 @@ static int ndb_builder_push_packed_id(struct ndb_builder *builder,
unsigned char *id, unsigned char *id,
union ndb_packed_str *pstr) union ndb_packed_str *pstr)
{ {
if (ndb_builder_find_str(builder, (const char*)id, 32, pstr)) { // Don't both find id duplicates. very rarely are they duplicated
pstr->packed.flag = NDB_PACKED_ID; // and it slows things down quite a bit. If we really care about this
return 1; // 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)) { if (ndb_builder_push_str(builder, (const char*)id, 32, pstr)) {
pstr->packed.flag = NDB_PACKED_ID; pstr->packed.flag = NDB_PACKED_ID;