Commit Graph

24 Commits

Author SHA1 Message Date
fiatjaf
55a43e46b7 use xhex everywhere. 2025-11-23 06:57:54 -03:00
fiatjaf
7289da9c72 improve/refactor websocket connections hoping this will fix the undetected disconnections we're seeing.
this commit also remove all the sonic envelope parsing and reintroduces filters in REQ as a slice instead of as a singleton.

why? well, the sonic stuff wasn't really that fast, it was a little bit but only got fast enough once I introduced unsafe conversions between []byte and string and did weird unsafe reuse of []byte in order to save the values of tags, which would definitely cause issues in the future if the caller wasn't aware of it (and even if they were, like myself).

and the filters stuff is because we abandoned the idea of changing NIP-01 to only accept one filter per REQ.
2025-07-10 22:58:37 -03:00
fiatjaf
15c6093c9b define a nostr.Kind type for event kinds, make adjustments everywhere and fix some horrible bugs with mmm, lmdb and badger querying and deleting. 2025-04-20 11:15:41 -03:00
fiatjaf
b4268d649c a bunch of [32]byte conversions. still more needed. 2025-04-14 17:47:53 -03:00
fiatjaf
c64ebde59d fix sonic parsing req envelopes with limit/since/until. 2025-03-14 20:08:56 -03:00
fiatjaf
cecc71cd81 fix and improve envelope stuff again, deal with messages as strings on all envelope parsing steps. 2025-03-12 00:18:11 -03:00
fiatjaf
a37dd05344 remove simdjson because sonic is just better. 2025-03-07 21:49:48 -03:00
fiatjaf
7c57ad860a add more ParseMessage tests. 2025-03-07 15:50:55 -03:00
fiatjaf
8d7e854779 some fixes to sonic and make it faster by reusing arrays.
BenchmarkParseMessage/relay/jsonstdlib-4              216   5651451 ns/op
BenchmarkParseMessage/relay/easyjson-4                313   3703457 ns/op
BenchmarkParseMessage/relay/simdjson-4                469   2606309 ns/op
BenchmarkParseMessage/relay/sonic-4                   966   1268594 ns/op

BenchmarkParseMessage/client/jsonstdlib-4             216   5524239 ns/op
BenchmarkParseMessage/client/easyjson-4               422   2756370 ns/op
BenchmarkParseMessage/client/simdjson-4               519   2298477 ns/op
BenchmarkParseMessage/client/sonic-4                  644   1860583 ns/op
2025-03-07 15:38:22 -03:00
fiatjaf
39bde22639 sonic ast visitor approach. now we're getting faster.
BenchmarkParseMessage/relay/jsonstdlib-4              206   8630635 ns/op
BenchmarkParseMessage/relay/easyjson-4                278   4311793 ns/op
BenchmarkParseMessage/relay/simdjson-4                422   2943387 ns/op
BenchmarkParseMessage/relay/sonic-4                   849   1576884 ns/op

BenchmarkParseMessage/client/jsonstdlib-4             196   6140585 ns/op
BenchmarkParseMessage/client/easyjson-4               385   2826706 ns/op
BenchmarkParseMessage/client/simdjson-4               405   2628675 ns/op
BenchmarkParseMessage/client/sonic-4                  552   2413731 ns/op
2025-03-07 11:03:09 -03:00
fiatjaf
c9411a3c5b depressing sonic json decoder implementation, breakingly force COUNT to use a single filter, reorganize envelope tests. 2025-03-06 19:34:36 -03:00
fiatjaf
4fb6fcd9a2 make simdjson great again.
now it is generally a little faster than the easyjson approach.

goos: linux
goarch: amd64
pkg: github.com/nbd-wtf/go-nostr
cpu: AMD Ryzen 3 3200G with Radeon Vega Graphics
BenchmarkParseMessage/stdlib-4         	      90	  15616341 ns/op
BenchmarkParseMessage/easyjson-4       	     110	  11306466 ns/op
BenchmarkParseMessage/simdjson-4       	     162	   7779856 ns/op
PASS
ok  	github.com/nbd-wtf/go-nostr	5.547s
2025-03-05 23:56:15 -03:00
fiatjaf
a82780e82e fix these simdjson benchmarks so others can run them. 2025-02-26 17:12:49 -03:00
fiatjaf
56e9a5a709 implement envelope, event and filter parsing with simdjson-go. 2025-02-25 17:57:15 -03:00
fiatjaf
72d9aac9b1 replace all ocurrences of encoding/json with json-iterator so we get rid of HTML escaping and hopefully get faster too. 2024-12-03 00:49:27 -03:00
K
c91e7b9765 using testify instead of testing.T methods. (#143) 2024-09-09 07:20:56 -03:00
fiatjaf
abe84f9089 improve COUNT envelope codec and add a test. 2024-05-20 08:26:13 -03:00
fiatjaf
b43d0e374a reorder json serialization to write "kind" first and adjust tests. 2024-04-25 18:30:38 -03:00
fiatjaf
1bccebbf2a fix ParseMessage() so it works with CLOSED and improve tests. 2023-12-09 11:29:14 -03:00
fiatjaf
fa20f84ec7 support CLOSED messages. 2023-11-28 18:25:46 -03:00
fiatjaf
29646d8bec fix ok envelope test.
fixes https://github.com/nbd-wtf/go-nostr/pull/106
2023-11-05 13:35:45 -03:00
boreq
b984a598cb Fix panic in ParseMessage
There is a chance the function can panic if a comma is included in the
input which is invalid.
2023-06-20 12:13:48 -03:00
Isaque Veras
58d56abe05 fix: removing redundancy 2023-06-12 08:18:29 -03:00
fiatjaf
f7ce78d7f8 add custom envelope types with json codecs. 2023-05-09 16:31:10 -03:00