Closed hoylen closed 4 years ago
Yeah so it seems that the imports don't matter anymore. That makes sense since they only did for dart:mirrors usage. If you want, feel free to improve the import paths etc to something more convenient. Perhaps dropping all but pointycastle.dart
would be possible.
One thing we need to be careful about is to make sure we never use the registry internally. Because then the code increase may come unexpectedly.
One optimization we could make is to, when Digest("SHA-256")
is called, not load all registry information, but just the digest registry information. They are quite clearly categorized, so they could be lazily-loaded individually.
Ideally, there would be one file to import if you want to use the registry (but it doesn't let you use any of the constructors), and another file that you import if you want to use the constructors (but it doesn't let you use the registry). That is easy to explain/document and gives people the option to deliberately avoid using the registry (with no risk of accidentally using it).
I'll leave this for now, since I have to get back to my original task of writing code to read/write SSH public and private key files...
Following the discussion on the behaviour of the registry in https://github.com/PointyCastle/pointycastle/pull/212, I have improved the text describing the differences between using the registry and not using the registry.
Registry use does increase code size
I have also done some more testing, and it looks like the tree shaking (in Dart 2.7.0) does do a good job. For a test Web page that just calculates SHA-256:
If the registry is not used (i.e. used the constructor on
SHA256Digest
), importing everything by importing "package:pointycastle/export.dart" or importing just "package:pointycastle/digests/sha256.dart" both produced the same size JavaScripts.If the registry is used (i.e.
Digest("SHA-256")
), the JavaScripts increased by 364 KiB . It was the same increase, either importing "package:pointycastle/pointycastle.dart", "package:pointycastle/export.dart" or just "package:pointycastle/digests/sha256.dart".The JavaScripts are probably not "exactly" the same size, but occupied the exact same block count as reported by du.
But actual increase may differ
In an example that used RSA classes for key generation, signature/verification, and encryption/decryption, the size difference between without-registry and with-registry was only 8 KiB. So I guess the registry does increase the size of the total program's code, but the amount may or may not be significant compared to the other code that is imported from Pointy Castle.
Here are the numbers:
Doesn't seem to make much difference to performance
I did not notice any statistically meaningful differences in performance for the SHA-256 examples.
In particular, I was expected importing "export.dart" would be slower than importing just "sha256.dart". But I didn't see that (not to the 0.01 second resolution produced by the Unix time program).
What to tell users
So maybe programmers can just choose between importing "pointycastle.dart" or "export.dart". Compared to just importing "export.dart", there doesn't seem to be any benefit of going to the trouble of finding out and typing in individual imports for each individual library.
Or even simpler, maybe the advice should be to simply import (what is currently called) "export.dart" for all situations. It works with both the registry and without the registry.