1
0
Files
electrum/electrum
SomberNight f429af7d01 lnutil: cache validate_features() results
channel_db.load_data() is slow, slowing down startup time (when trampoline is disabled).
util.list_enabled_bits() is one of the main contributors to the slowness, called by validate_features().

One could argue that we could even simply *not* call validate_features for gossip messages as part of load_data,
as they have already been validated before storing them in the db. However re-validating them there is a good
clean-up/sanity check IMO. Note that what is considered "valid" can change over time, so just because validate_features
passed when we originally received and stored a gossip message, it might no longer be valid a year later if the bolts change.

This caching decreases the time needed for load_data on two different machines / gossip dbs as below:
47 sec -> 10 sec
18 sec -> 6 sec

If instead of caching, I just rm the validate_features() calls, the benchmarks are almost identical, within noise.
That is, the cache looks really effective.
(the rest of the slowness is mostly due to lnmsg.decode_msg)

```
>>> lnutil.validate_features.cache_info()
CacheInfo(hits=172674, misses=287, maxsize=1000, currsize=277)
```

-----

We could alternatively directly cache util.list_enabled_bits (instead of validate_features).
That would be a bit slower and might end up using a lot more memory in some cases I think, but maybe conceptually would be cleaner.
Also note that if validate_features() raises an exception, that is not cached.
2025-04-04 18:24:50 +00:00
..
2024-09-18 15:48:38 +00:00
2025-02-04 09:43:40 +01:00
2022-10-20 18:43:54 +00:00
2024-05-30 13:08:13 +00:00
2025-02-10 14:22:50 +01:00
2025-04-02 16:21:59 +00:00
2024-10-22 09:26:36 +02:00
2025-03-10 19:42:37 +01:00
2025-04-02 14:56:53 +00:00
2025-03-05 10:29:26 +01:00
2023-02-17 11:43:11 +00:00
2025-02-19 14:29:02 +01:00
2025-02-19 14:29:02 +01:00
2025-03-13 10:17:10 +01:00
2025-04-02 16:21:59 +00:00
2024-06-04 13:42:57 +00:00
2025-03-17 10:47:19 +01:00
2024-11-29 17:09:29 +08:00
2022-10-31 16:13:22 +00:00
2024-05-22 15:26:26 +00:00
2025-04-02 16:21:59 +00:00
2023-04-24 12:58:26 +00:00
2022-10-31 16:13:22 +00:00
2024-04-24 14:14:31 +00:00
2025-04-03 14:39:05 +02:00
2024-05-20 16:57:11 +02:00
2023-12-04 14:15:39 +08:00
2025-04-03 14:39:05 +02:00
2025-04-02 16:21:59 +00:00
2025-02-28 16:46:29 +00:00
2025-04-02 16:21:59 +00:00
2025-01-23 12:58:28 +01:00