Git Product home page Git Product logo

Comments (12)

sseemayer avatar sseemayer commented on August 10, 2024

Please have a look at https://github.com/sseemayer/keepass-rs/blob/master/README.md#installation , especially the note about performance :)

from keepass-rs.

Narigo avatar Narigo commented on August 10, 2024

As stated in the other PR, even with the flags enabled, it still took a while to open. Is there another flag I should be using other than what I have written down in the comment?

Regarding the flags itself: Do you know whether it is possible to put the necessary flag into Cargo when compiling as dependency? I'd like to not have the user have to analyse dependencies and set the flags that would be necessary for each of them. There is a setting for rustflags in Cargo configuration but I've never used or tried that...

from keepass-rs.

sseemayer avatar sseemayer commented on August 10, 2024

Sorry for the short reply before. This seems to be a real issue with the performance of the AES key derivation.

I can also see that even with the compiler flags and doing a release build, this library is still considerably slower than what e.g. keepassxc needs to derive the key.

On my mobile Core i5-8250U, with the CFLAGS set, a release run of the tests::open_kdbx4_with_password_kdf_aes_cipher_aes takes 17 seconds to open while opening the same database is instantaneous.

from keepass-rs.

sseemayer avatar sseemayer commented on August 10, 2024

Hang on, no! If I export the correct RUSTFLAGS and do a release build, the test completes in less than half a second for me. It seems that my first attempt at adding the config via a file was incorrect.

For a debug run of the test, I still manage to complete it within 17 seconds.

from keepass-rs.

sseemayer avatar sseemayer commented on August 10, 2024

I've added the rustflags to the cargo config now as well. Let me know if that together with a Release build helps bring the loading time down.

from keepass-rs.

Narigo avatar Narigo commented on August 10, 2024

I have updated to version 0.4.7 now and tried to set the RUSTFLAGS in .cargo/config.toml as well as having it as environment variables during the run. The following output of the Docker environment yield very long opening times still with kdbx 3.1 files:

root@cb29c1f5ec07:/app# time RUSTFLAGS="-C target-cpu=native" cargo run --release test/test.kdbx test/test2.kdbx --password-a demopass --password-b demopass --no-color
    Finished release [optimized] target(s) in 0.18s
     Running `target/release/keepass-diff test/test.kdbx test/test2.kdbx --password-a demopass --password-b demopass --no-color`
+ [Root, Another group, In another group]
- [Root, Some group, Sub-Group 2 of group, Walked, Password = line]
+ [Root, Some group, Sub-Group 2 of group, Walked, Password = plank]
+ [Root, Some group, Sub-Group 2 of group, Whatever, that = means]
- [Root, Some group, In a group]
+ [Root, One more]


real    0m0.421s
user    0m0.238s
sys     0m0.051s
root@cb29c1f5ec07:/app# time RUSTFLAGS="-C target-cpu=native" cargo run --release test/issue-24-kdbx-3.1/Test1.kdbx test/issue-24-kdbx-3.1/Test2.kdbx --password-a Test1 --password-b Test2 --no-color
    Finished release [optimized] target(s) in 0.17s
     Running `target/release/keepass-diff test/issue-24-kdbx-3.1/Test1.kdbx test/issue-24-kdbx-3.1/Test2.kdbx --password-a Test1 --password-b Test2 --no-color`
- [Root, Test1]
+ [Root, Test2]


real    0m57.413s
user    0m57.281s
sys     0m0.049s

Maybe I'm still doing something wrong here...?

The code I'm testing with is in branch update-dependencies in the keepass-diff repository: https://github.com/Narigo/keepass-diff/tree/8b8e46d61dc0efc80bef7fc310262d18c0140f63

By the way, since I've updated to 0.4.7, the Value::Bytes pattern had to be implemented. Does my implementation even make sense? Or could a bytes array be anything in Keepass, so I maybe should try to convert it to a hash value and test against that?

from keepass-rs.

Narigo avatar Narigo commented on August 10, 2024

Hmm, using cargo install --path . seems to do some other optimizations? At least it's down to 7s now, but that's still quite long compared to the 1s for other kdbx files, isn't it?

Edit: Sorry, that was for 0.4.5. Using 0.4.7 takes still around 1 minute

from keepass-rs.

sseemayer avatar sseemayer commented on August 10, 2024

Sorry, I cannot reproduce this - Testing on 8b8e46,

Your first invocation

$ time RUSTFLAGS="-C target-cpu=native" cargo run --release test/test.kdbx test/test2.kdbx --password-a demopass --password-b demopass --no-color

takes me 0.07s and

your second invocation

$ time RUSTFLAGS="-C target-cpu=native" cargo run --release test/issue-24-kdbx-3.1/Test1.kdbx test/issue-24-kdbx-3.1/Test2.kdbx --password-a Test1 --password-b Test2 --no-color

takes 6.35s.

timing

If I open the same two database files as in your second invocation using keepassxc, this takes about 2 seconds for each of the databases (I didn't really time this but this is a rough estimate), so it looks like this is close to an "optimal" key derivation speed.

from keepass-rs.

sseemayer avatar sseemayer commented on August 10, 2024

Since the key derivation function for the slow databases is AES, can you confirm that your system's CPU is supporting AES hardware instructions (the aes flag)?

$ grep flags /proc/cpuinfo | head -n1
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp flush_l1d

from keepass-rs.

Narigo avatar Narigo commented on August 10, 2024

I'm doing this on a Mac with Docker. In Docker, it shows me the following (= I guess so?):

root@cadaa7cf56f6:/app# grep flags /proc/cpuinfo | head -n1
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht pbe syscall nx pdpe1gb lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid pni pclmulqdq dtes64 ds_cpl ssse3 sdbg fma cx16 xtpr pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch pti fsgsbase bmi1 avx2 bmi2 erms xsaveopt arat

from keepass-rs.

sseemayer avatar sseemayer commented on August 10, 2024

Yeah, it looks like it's supported. Hmm.

Another thing we could check is whether the release binary gets compiled with hardware AES instructions by disassembling it, e.g.:

$ objdump -d target/release/keepass-diff | grep vaes | cut -f3 | cut -f1 -d ' ' | sort | uniq -c | sort -rn
    143 vaesenc
    117 vaesdec
     13 vaeskeygenassist
     13 vaesimc
     11 vaesenclast
      9 vaesdeclast

from keepass-rs.

Narigo avatar Narigo commented on August 10, 2024

I think this should be okay now: Without the usage of docker, I get a lot better performance, so it's probably not really the fault of the keepass module. It still takes a few seconds to open these files but the flags really work well enough I suppose. See Narigo/keepass-diff#24 (comment) as well. Thanks for your help in debugging this and sorry for the additional noise...! 🙂

from keepass-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.