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

steven_blocks: reduce optimizations in release, closes #184 #255

Merged
merged 31 commits into from
Jan 5, 2020

Conversation

iceiix
Copy link
Owner

@iceiix iceiix commented Jan 4, 2020

#184 steven_blocks: could not compiler under windows? memory allocation of 15728640 bytes failed, STATUS_STACK_BUFFER_OVERRUN

steven $ time cargo build --release
    Finished release [optimized] target(s) in 252m 07s

real	252m7.337s
user	196m14.679s
sys	14m12.878s

iceiix added 17 commits January 3, 2020 17:19
rm -rf target/release/deps/steven_blocks-* ; time cargo build --release

0.188s
Requires nightly, `rustup default nightly`
The define_blocks! macro expands in about 9 seconds:

note: trace_macro
    --> blocks/src/lib.rs:486:1
     |
486  | / define_blocks! {
487  | |     Air {
488  | |         props {},
489  | |         material material::Material {
...    |
5601 | |     }
5602 | | }
     | |_^
     |
     = note: expanding `define_blocks! { Air
[............]
note: trace_macro
   --> blocks/src/lib.rs:930:17
    |
930 |         variant format!("extended={},facing={}", extended, facing.as_string()),
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: expanding `format! { "extended={},facing={}", extended, facing . as_string () }`
    = note: to `$crate :: fmt :: format
            ($crate :: __export :: format_args !
             ("extended={},facing={}", extended, facing . as_string ()))`

^C  Building [=====================================================> ] 317/320: steven_blocks

real	0m9.936s
user	0m5.460s
sys	0m0.444s
Removes 1000 lines from bottom

real	1m43.476s
user	4m14.319s
sys	0m8.194s
This reverts commit 5e951f5.

time cargo rustc -- -Z time-passes

  time: 13.535	item-bodies checking
  time: 26.370	metadata encoding and writing
  time: 28.031	MIR borrow checking
  time: 3.550	LLVM passes
time: 85.748		total
real	1m52.989s
user	2m18.885s
sys	0m8.025s
blocks $ cargo clean ; time cargo rustc -- -Z time-passes

This reverts commit 32655a3.
… in crate `libc`

error[E0425]: cannot find function `pthread_atfork` in crate `libc`
   --> .cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.6.5/src/rngs/adapter/reseeding.rs:320:28
    |
320 |             unsafe { libc::pthread_atfork(None, None, Some(fork_handler)) };
    |                            ^^^^^^^^^^^^^^ not found in `libc`

   Compiling quote v0.6.10
   Compiling syn v0.15.23
error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.
error: could not compile `rand`.
warning: build failed, waiting for other jobs to finish...
error: build failed

real	0m7.047s
user	0m20.843s
sys	0m2.494s

steven_blocks v0.0.1 (steven/blocks)
├── cgmath v0.17.0
│   ├── approx v0.3.2
│   │   └── num-traits v0.2.6
│   ├── num-traits v0.2.6 (*)
│   ├── rand v0.6.5
│   │   ├── libc v0.2.9
@iceiix iceiix closed this Jan 4, 2020
@iceiix iceiix deleted the blocks_macros branch January 4, 2020 20:28
@iceiix iceiix restored the blocks_macros branch January 4, 2020 21:01
@iceiix iceiix reopened this Jan 4, 2020
iceiix added 6 commits January 4, 2020 17:58
warning: this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter` (due to autoref coercions), but that might change in the future when `IntoIterator` impls for arrays are added.
   --> src/entity/player.rs:363:11
    |
363 |         ].into_iter().enumerate() {
    |           ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
    |
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #66145 <rust-lang/rust#66145>
warning: use of deprecated item 'std::error::Error::description': use the Display impl or to_string()
   --> src/protocol/mod.rs:981:40
    |
981 |             Error::IOError(ref e) => e.description(),
    |                                        ^^^^^^^^^^^
    |
    = note: `#[warn(deprecated)]` on by default
warning: the cargo feature `profile-overrides` is now stable and is no longer necessary to be listed in the manifest
iceiix added a commit that referenced this pull request Jan 5, 2020
 (#255)

Reduce to "basic optimizations" for the steven_blocks module, so it
doesn't take hours of time and gigabytes of memory to compile. The main
program and other code still builds with full optimizations in release
mode, to accomplish this, the profile-overrides feature is required so
we also switch to nightly Rust (to be switched to 1.41+ in #258).

* Update to rustc 1.42.0-nightly (760ce94c6 2020-01-04)

* Update builds.sr.ht to use +nightly

* Override opt-level=1 for steven_blocks using profile-overrides
@iceiix iceiix merged commit b6aac4c into master Jan 5, 2020
iceiix added a commit that referenced this pull request Jan 5, 2020
iceiix added a commit that referenced this pull request Jan 10, 2020
Improves fix for #184, whereas #255 reduced optimizations,
we now address the underlying compiler limitation and split out
the one massive lazy_static! initialization function, into
one function per block in the block_registration_functions module.

Previous build time, with opt-level=1:

% time cargo build --release
   Compiling steven_blocks v0.0.1
    Finished release [optimized] target(s) in 21.24s
cargo build --release  31.80s user 0.71s system 152% cpu 21.276 total

With this change, opt-level=3 and the function splitting fix:

% time cargo build --release
   Compiling steven_blocks v0.0.1
    Finished release [optimized] target(s) in 30.80s
cargo build --release  40.26s user 0.86s system 133% cpu 30.850 total

Full optimizations are expectedly slightly slower, but this is still
much much _much_ faster than before this refactoring, where this crate
would take up to an unbelievable 5 hours (and tens of GB of RAM). Long
story short, we're now back to full optimizations and stable Rust.
iceiix added a commit that referenced this pull request Jan 10, 2020
Improves fix for #184, whereas #255 reduced optimizations,
we now address the underlying compiler limitation and split out
the one massive lazy_static! initialization function, into
one function per block in the block_registration_functions module.

Previous build time, with opt-level=1:

% time cargo build --release
   Compiling steven_blocks v0.0.1
    Finished release [optimized] target(s) in 21.24s
cargo build --release  31.80s user 0.71s system 152% cpu 21.276 total

With this change, opt-level=3 and the function splitting fix:

% time cargo build --release
   Compiling steven_blocks v0.0.1
    Finished release [optimized] target(s) in 30.80s
cargo build --release  40.26s user 0.86s system 133% cpu 30.850 total

Full optimizations are expectedly slightly slower, but this is still
much much _much_ faster than before this refactoring, where this crate
would take up to an unbelievable 5 hours (and tens of GB of RAM). Long
story short, we're now back to full optimizations and stable Rust.

Thanks to dtolnay on the Rust programming language forum for suggesting
this technique, https://users.rust-lang.org/t/5-hours-to-compile-macro-what-can-i-do/36508/2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant