Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use a binary format for wallet files #144

Open
PiRK opened this issue Oct 25, 2021 · 2 comments
Open

use a binary format for wallet files #144

PiRK opened this issue Oct 25, 2021 · 2 comments

Comments

@PiRK
Copy link
Collaborator

PiRK commented Oct 25, 2021

The Electrum wallet files contain the entire transaction history for a wallet, and thus can reach significant sizes (tens of megabytes). The transaction They are currently saved as JSON text, sometimes encrypted.

This could all be improved significantly by using a more compact data format than JSON for disk storage. A structured binary file would reduce the disk space usage, and using a file format that allows for an easy access to some data without having to read/parse all of it would improve performance significantly.

The following formats come to mind:

  • sqlite (database format)
  • HDF5 (easy to use data format with built-in indexing, compression....); drawback: dependency on numpy (+300MB packages)
@PiRK
Copy link
Collaborator Author

PiRK commented Dec 3, 2021

I did some profiling by tweaking the JSON output format. With a very large wallet (>100 MB), there are some potential gains by writing compact unsorted JSON:

diff --git a/electroncash/storage.py b/electroncash/storage.py
index fd872d1d1..08e685c00 100644
--- a/electroncash/storage.py
+++ b/electroncash/storage.py
@@ -120,8 +120,10 @@ class JsonDB(PrintError):
             return
         s = json.dumps(
             self.data,
-            indent=4 if self.output_pretty_json else None,
-            sort_keys=self.output_pretty_json,
+            indent=None,
+            sort_keys=False,
             cls=util.MyEncoder
         )
         s = self.encrypt_before_writing(s)

sort,indent
| 15.489| |03| [profiler] WalletStorage.write 0.9943

no sort, indent
| 16.008| |03| [profiler] WalletStorage.write 0.8581

no sort, no indent
| 15.378| |05| [profiler] WalletStorage.write 0.4795

@PiRK
Copy link
Collaborator Author

PiRK commented Dec 7, 2021

Related discussion: spesmilo#4823

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants
@PiRK and others