Oddbean new post about | logout
 Now Blowater's native decryption is roughly 15X faster than any NIP-07 extensions that use nostr-tools / NDK to decrypt.

Loading & Decrypt 3850 events took
2199 ms with Sign In with Nsec (nostr.ts)
31123 ms with Alby (nostr-tools)

15X improvement! 
 @Alby cc 
 Yes, Alby can consider using nostr.ts to just do the decryption part instead of nostr-tools.

Or I have to release Blowater as a NIP-07 extension because most users don't want to sign in Blowater with nsec.

Same goes to nostr:nprofile1qqsrx4k7vxeev3unrn5ty9qt9w4cxlsgzrqw752mh6fduqjgqs9chhgpr9mhxue69uhhyetvv9ujuumwdae8gtnnda3kjctv9uqsuamnwvaz7tmwdaejumr0dshsz9mhwden5te0wfjkccte9ehx7um5wghxyctwvshsd5c0fz 
 What’s the link to the repo? 
 Spring's decryption is in native code, I didn't measure the performance but from your description of the issue I'd say it's probably js-specific problem. 
 That’s good to know. Is there a way for client devs to debug inside Spring? 
 Not really, unfortunately. You'd have to use mobile Chrome and connect it to desktop dev console to debug properly. Spring only shows logs on the About page, and even those aren't convenient at all. 
 What did you do? I have an open PR to Alby to cache shared key generation, which helps a lot, but it sounds like you might have more going on. 
 Cache shared key makes it 3X faster which I have done months ago. What I did just now was to not using scure to decode base64 to UintArray, instead, just use atob which is 20X faster. 
 Wow, is atob faster because it's native code? Why did they roll their own? 
 scure.js, at least the version I am using seemed to have a recursive implementation. Only nostr:nprofile1qqs8evfumcr8pevs7qkta84qlnc7qhkmchxg5syhx8a9gdjyqxqu78gpz4mhxue69uhhyetvv9ujuerpd46hxtnfduhszxthwden5te0wfjkccte9e3xcmmhv96x2u3wv9c8qtcppemhxue69uhkummn9ekx7mp0fxcf3v  knows why.

nostr.ts 's original decrypt is copied from nostr-tools months ago. I remember that nostr:nprofile1qqs8evfumcr8pevs7qkta84qlnc7qhkmchxg5syhx8a9gdjyqxqu78gpz4mhxue69uhhyetvv9ujuerpd46hxtnfduhszxthwden5te0wfjkccte9e3xcmmhv96x2u3wv9c8qtcppemhxue69uhkummn9ekx7mp0fxcf3v  has released new versions since then but I never bothered to update. Maybe it's now faster.

I am not sure if Alby uses the exact nostr-tools decrypt or not. 
 Alby has no dependency on nostr-tools last I looked. You should PR to scure, that would be a huge gain for a lot of people! 
 I cannot reproduce your gains. I'm trying to improve the performance of our web-signer for batch-processing of decrypts. 

I copied your ende.ts and replaced nostr-tools with it, absolutely no effect. In fact chrome profiler shows no time spent in base64 codec, all the time is spent on crypto stuff - keygen and cipher. 

Do you have a reproducible benchmark code that shows 4k events decrypted in 2 sec? Was your measurement made in the browser or nodejs? 

Are you sure shared key caching wasn't the trick? I added that and got significant improvement, although didn't work on measuring it specifically (my focus was on nip46 flow where other stuff is also slow).