rust 第一次“货运”用了46分钟,第二次则用了28分钟:怎么这么慢?

rdrgkggo  于 2023-03-18  发布在  其他
关注(0)|答案(1)|浏览(65)

下面是我的cargo.toml

[package]
name = "trysuisdk"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
sui-sdk = { git = "https://github.com/MystenLabs/sui" }
tokio = "1.26.0"
directories = "4.0.1"
anyhow = "1.0.69"

[dependencies.sui-keys]
git = "https://github.com/MystenLabs/sui"

看起来很简单,代码更简单:

use std::str::FromStr;
use sui_sdk::{
    types::{
        base_types::{ObjectID, SuiAddress},
        crypto::{Signature, SignatureScheme},
        messages::Transaction,
    },
    SuiClient,
};
use sui_keys::{key_derive, keystore::{self, AccountKeystore}, keypair_file};
use anyhow::{anyhow, Error};
use tokio;
use std::path::PathBuf;
use std::env;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
    let mut current_dir = env::current_dir()?;
    current_dir.push(r"keystores");
    current_dir.set_extension(r"keystore");
    let mut new_keystore = keystore::FileBasedKeystore::new(&current_dir)?;

    for i in 0..=4 {
        new_keystore.generate_and_add_new_key(SignatureScheme::ED25519, None)?;
    }
    new_keystore.save();
    Ok(())
}

上下文(实际上并不重要)是生成4个SUI的密钥对并将它们写入一个文件。
第一次运行耗时46分钟,以下是日志:

\suisdk>cargo run 
    Blocking waiting for file lock on build directory
   Compiling num-integer v0.1.45
   Compiling futures-util v0.3.27
   Compiling ring v0.16.20
   Compiling outref v0.5.1
   Compiling vsimd v0.8.0
   Compiling bytes-utils v0.1.3
   Compiling xmlparser v0.13.5
   Compiling urlencoding v2.1.2
   Compiling snafu v0.7.4
   Compiling num-bigint v0.4.3
   Compiling num-iter v0.1.43
   Compiling chrono v0.4.23    
   Compiling base64-simd v0.8.0
   Compiling aws-smithy-xml v0.54.4
   Compiling quick-xml v0.27.1
   Compiling aws-smithy-types v0.54.4
   Compiling num-rational v0.4.1
   Compiling webpki v0.22.0
   Compiling sct v0.7.0
   Compiling h2 v0.3.16
   Compiling num v0.4.0
   Compiling rustls v0.20.8
   Compiling move-core-types v0.0.4 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling futures-executor v0.3.27
   Compiling tower v0.4.13
   Compiling futures v0.3.27
   Compiling webpki-roots v0.22.6
   Compiling tokio-rustls v0.23.4
   Compiling ark-serialize v0.4.1
   Compiling soketto v0.7.1
   Compiling axum-core v0.3.3
   Compiling ark-ff v0.4.1
   Compiling quinn-proto v0.9.2
   Compiling chrono-tz v0.6.3
   Compiling der-parser v8.2.0
   Compiling rcgen v0.9.3
   Compiling hyper v0.14.25
   Compiling move-binary-format v0.0.3 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling move-command-line-common v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling tower-http v0.3.5
   Compiling move-ir-types v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling move-bytecode-source-map v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling move-ir-to-bytecode-syntax v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling move-bytecode-verifier v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling move-ir-to-bytecode v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling move-coverage v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling move-read-write-set-types v0.0.3 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling hyper-rustls v0.23.2
   Compiling move-compiler v0.0.1 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling ark-poly v0.4.1
   Compiling jsonrpsee-core v0.16.2
   Compiling ark-relations v0.4.0
   Compiling axum v0.6.7
   Compiling ark-ec v0.4.1
   Compiling hyper-timeout v0.4.1
   Compiling quinn-udp v0.3.2
   Compiling ark-snark v0.4.0
   Compiling x509-parser v0.14.0
   Compiling tera v1.17.1
   Compiling quinn v0.9.3
   Compiling ark-r1cs-std v0.4.0
   Compiling reqwest v0.11.14
   Compiling tonic v0.8.3
   Compiling move-disassembler v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling jsonrpsee-client-transport v0.16.2
   Compiling move-model v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling ark-crypto-primitives v0.4.0
   Compiling anemo v0.0.0 (https://github.com/mystenlabs/anemo.git?rev=d4017b6cefad7ebc5e84b5c6b8eeff4668f719ff#d4017b6c)
   Compiling move-vm-types v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling sqlx-rt v0.6.2 (https://github.com/huitseeker/sqlx?branch=update_libsqlite3#fa4613e7)
   Compiling governor v0.5.1
   Compiling simplelog v0.9.0
   Compiling ark-ff v0.3.0
   Compiling sqlx-core v0.6.2 (https://github.com/huitseeker/sqlx?branch=update_libsqlite3#fa4613e7)
   Compiling ark-groth16 v0.4.0
   Compiling move-vm-runtime v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling console-api v0.4.0
   Compiling move-docgen v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling move-abigen v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling move-stackless-bytecode v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling move-errmapgen v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling move-prover-boogie-backend v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling anemo-tower v0.0.0 (https://github.com/mystenlabs/anemo.git?rev=d4017b6cefad7ebc5e84b5c6b8eeff4668f719ff#d4017b6c)
   Compiling ark-ec v0.3.0
   Compiling jsonrpsee-wasm-client v0.16.2
   Compiling jsonrpsee-ws-client v0.16.2
   Compiling jsonrpsee-server v0.16.2
   Compiling jsonrpsee-http-client v0.16.2
   Compiling ark-bls12-381 v0.4.0
   Compiling move-bytecode-utils v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling diesel v2.0.3
   Compiling move-prover v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling fastcrypto-zkp v0.1.0 (https://github.com/MystenLabs/fastcrypto?rev=5454b7f65632b35cb9503fb14ac0aca3823b5706#5454b7f6)
   Compiling move-package v0.1.0 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling jsonrpsee v0.16.2
   Compiling move-stdlib v0.1.1 (https://github.com/move-language/move?rev=8729cf2445696cb29f1e0ca06df7d09cf3c2c55f#8729cf24)
   Compiling ark-bls12-377 v0.3.0
   Compiling diesel_migrations v2.0.0
   Compiling anemo-cli v0.0.0 (https://github.com/mystenlabs/anemo.git?rev=d4017b6cefad7ebc5e84b5c6b8eeff4668f719ff#d4017b6c)
   Compiling console-subscriber v0.1.8
   Compiling sqlx v0.6.2 (https://github.com/huitseeker/sqlx?branch=update_libsqlite3#fa4613e7)
   Compiling tonic-health v0.8.0
   Compiling axum-extra v0.4.2
   Compiling axum-server v0.4.6
   Compiling criterion v0.4.0
   Compiling rstest v0.16.0
   Compiling duration-str v0.4.0
   Compiling aws-smithy-http v0.54.4
   Compiling aws-smithy-async v0.54.4
   Compiling aws-smithy-json v0.54.4
   Compiling aws-smithy-http-tower v0.54.4
   Compiling aws-smithy-client v0.54.4
   Compiling aws-credential-types v0.54.1
   Compiling aws-sigv4 v0.54.1
   Compiling aws-smithy-query v0.54.4
   Compiling aws-types v0.54.1
   Compiling aws-sig-auth v0.54.1
   Compiling aws-http v0.54.1
   Compiling aws-endpoint v0.54.1
   Compiling aws-sdk-sts v0.24.0
   Compiling aws-sdk-sso v0.24.0
   Compiling workspace-hack v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling shared-crypto v0.0.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-macros v0.7.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-protocol-config v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling typed-store v0.4.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling mysten-common v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling mysten-util-mem v0.11.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling mysten-network v0.2.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling prometheus-closure-metric v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling telemetry-subscribers v0.2.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-cost-tables v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling mysten-metrics v0.7.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling aws-config v0.54.1
   Compiling narwhal-crypto v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-open-rpc v0.0.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling narwhal-config v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling narwhal-dag v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-types v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling object_store v0.5.4
   Compiling narwhal-types v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling narwhal-network v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling narwhal-storage v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling narwhal-consensus v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-verifier v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-keys v0.0.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-framework-build v0.0.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-json v0.0.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-json-rpc-types v0.0.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling narwhal-primary v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling narwhal-worker v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-framework v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling narwhal-executor v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling narwhal-node v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-simulator v0.7.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-adapter v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-storage v0.1.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-transaction-builder v0.0.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-config v0.0.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-network v0.0.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-core v0.28.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-json-rpc v0.0.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling sui-sdk v0.28.0 (https://github.com/MystenLabs/sui#aa1a78e7)
   Compiling trysuisdk v0.1.0 (F:\rust_projects\suisdk)
warning: unused import: `std::str::FromStr`
 --> src\main.rs:1:5
  |
1 | use std::str::FromStr;
  |     ^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused imports: `ObjectID`, `Signature`, `SuiAddress`, `SuiClient`, `messages::Transaction`
 --> src\main.rs:4:22
  |
4 |         base_types::{ObjectID, SuiAddress},
  |                      ^^^^^^^^  ^^^^^^^^^^
5 |         crypto::{Signature, SignatureScheme},
  |                  ^^^^^^^^^
6 |         messages::Transaction,
  |         ^^^^^^^^^^^^^^^^^^^^^
7 |     },
8 |     SuiClient,
  |     ^^^^^^^^^

warning: unused imports: `key_derive`, `keypair_file`
  --> src\main.rs:10:16
   |
10 | use sui_keys::{key_derive, keystore::{self, AccountKeystore}, keypair_file};
   |                ^^^^^^^^^^                                     ^^^^^^^^^^^^

warning: unused imports: `Error`, `anyhow`
  --> src\main.rs:11:14
   |
11 | use anyhow::{anyhow, Error};
   |              ^^^^^^  ^^^^^

warning: unused import: `std::path::PathBuf`
  --> src\main.rs:13:5
   |
13 | use std::path::PathBuf;
   |     ^^^^^^^^^^^^^^^^^^

warning: unused variable: `i`
  --> src\main.rs:24:9
   |
24 |     for i in 0..=4 {
   |         ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: `trysuisdk` (bin "trysuisdk") generated 6 warnings
    Finished dev [unoptimized + debuginfo] target(s) in 46m 15s
     Running `target\debug\trysuisdk.exe`

在第二次运行cargo run时,花费了28分钟,下面是日志:

\suisdk>cargo run 
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on build directory
   Compiling trysuisdk v0.1.0 (F:\rust_projects\suisdk)
warning: unused import: `std::str::FromStr`
 --> src\main.rs:1:5
  |
1 | use std::str::FromStr;
  |     ^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused imports: `ObjectID`, `Signature`, `SuiAddress`, `SuiClient`, `messages::Transaction`
 --> src\main.rs:4:22
  |
4 |         base_types::{ObjectID, SuiAddress},
  |                      ^^^^^^^^  ^^^^^^^^^^
5 |         crypto::{Signature, SignatureScheme},
  |                  ^^^^^^^^^
6 |         messages::Transaction,
  |         ^^^^^^^^^^^^^^^^^^^^^
7 |     },
8 |     SuiClient,
  |     ^^^^^^^^^

warning: unused imports: `key_derive`, `keypair_file`
  --> src\main.rs:10:16
   |
10 | use sui_keys::{key_derive, keystore::{self, AccountKeystore}, keypair_file};
   |                ^^^^^^^^^^                                     ^^^^^^^^^^^^

warning: unused imports: `Error`, `anyhow`
  --> src\main.rs:11:14
   |
11 | use anyhow::{anyhow, Error};
   |              ^^^^^^  ^^^^^

warning: unused import: `std::path::PathBuf`
  --> src\main.rs:13:5
   |
13 | use std::path::PathBuf;
   |     ^^^^^^^^^^^^^^^^^^

warning: unused variable: `i`
  --> src\main.rs:24:9
   |
24 |     for i in 0..=4 {
   |         ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: unused `std::result::Result` that must be used
  --> src\main.rs:27:5
   |
27 |     new_keystore.save();
   |     ^^^^^^^^^^^^^^^^^^^^
   |
   = note: this `Result` may be an `Err` variant, which should be handled
   = note: `#[warn(unused_must_use)]` on by default

warning: `trysuisdk` (bin "trysuisdk") generated 7 warnings
    Finished dev [unoptimized + debuginfo] target(s) in 28m 26s
     Running `target\debug\trysuisdk.exe`

我的问题显然是:
1.为什么这么慢
1.如何加快速度?
谢谢大家!

更新/日期:2023年3月14日

/suisdk (master)
$ cargo run
   Compiling trysuisdk v0.1.0 (F:\rust_projects\suisdk)
warning: unused import: `Error`
 --> src\keys.rs:2:14
  |
2 | use anyhow::{Error, Result};
  |              ^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: `tokio`
 --> src\keys.rs:4:5
  |
4 | use tokio;
  |     ^^^^^

warning: `trysuisdk` (bin "trysuisdk") generated 2 warnings
    Finished dev [unoptimized + debuginfo] target(s) in 63m 00s
     Running `target\debug\trysuisdk.exe`

我猜现在更疯狂了!

tuwxkamq

tuwxkamq1#

我高度怀疑是铁 rust 分析仪导致了这个问题。
我找到了一个似乎有效的解决方案,但我不知道它是否是根本原因,因此,如果我确实解决了我的问题-它确实有效。

溶液

将 rust eclipse 分析仪的checkOnSave设置切换为false。

"rust-analyzer.checkOnSave": false

我的猜测是,因为我有VSCode的Auto Save打开和生 rust 分析器总是检查保存意味着它总是检查,因为VSCode总是保存,因此它干扰货物命令。

相关问题