Skip to content

Commit

Permalink
[DNM] Some absolute insanity performance hacks (#27204)
Browse files Browse the repository at this point in the history
* Some absolute insanity performance hacks

* Ok NOW its getting weird

* Adds a way of verifying if this is working

* Lets see how this goes

* Build Rust library

---------

Co-authored-by: paradisess13[bot] <165046124+paradisess13[bot]@users.noreply.github.com>
  • Loading branch information
AffectedArc07 and paradisess13[bot] authored Nov 14, 2024
1 parent a08dd17 commit e154414
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ _build_dependencies.sh @AffectedArc07
# Executables that need to be security-cleared
dreamchecker.exe @AffectedArc07
rustlibs.dll @AffectedArc07
rustlibs_prod.dll @AffectedArc07
rust_g.dll @AffectedArc07

### S34NW
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build_rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ jobs:
cp target/i686-unknown-linux-gnu/release/librustlibs.so ../tools/ci/librustlibs_ci.so
cp target/i686-pc-windows-gnu/release/rustlibs.dll ../rustlibs.dll
# Build the para-specific version
RUSTFLAGS='-C target-cpu=raptorlake' cargo build --release --target=i686-pc-windows-gnu
cp target/i686-pc-windows-gnu/release/rustlibs.dll ../rustlibs_prod.dll
git commit -a -m "Build Rust library" --allow-empty
git push origin
Expand Down
36 changes: 26 additions & 10 deletions code/__DEFINES/rust.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@

/* This comment bypasses grep checks */ /var/__rustlib

// IF we are on the production box, use a dll that has 0 compatibility of working with normal people's CPUs
// This works by allowing rust to compile with modern x86 instructionns, instead of compiling for a pentium 4
// This has the potential for significant speed upgrades with SIMD and similar
#ifdef PARADISE_PRODUCTION_HARDWARE
#define RUSTLIBS_SUFFIX "_prod"
#else
#define RUSTLIBS_SUFFIX ""
#endif

/proc/__detect_rustlib()
if(world.system_type == UNIX)
#ifdef CIBUILDING
Expand All @@ -16,27 +25,34 @@
return __rustlib = "tools/ci/librustlibs_ci.so"
#endif
// First check if it's built in the usual place.
if(fexists("./rust/target/i686-unknown-linux-gnu/release/librustlibs.so"))
return __rustlib = "./rust/target/i686-unknown-linux-gnu/release/librustlibs.so"
if(fexists("./rust/target/i686-unknown-linux-gnu/release/librustlibs[RUSTLIBS_SUFFIX].so"))
return __rustlib = "./rust/target/i686-unknown-linux-gnu/release/librustlibs[RUSTLIBS_SUFFIX].so"
// Then check in the current directory.
if(fexists("./librustlibs.so"))
return __rustlib = "./librustlibs.so"
if(fexists("./librustlibs[RUSTLIBS_SUFFIX].so"))
return __rustlib = "./librustlibs[RUSTLIBS_SUFFIX].so"
// And elsewhere.
return __rustlib = "librustlibs.so"
return __rustlib = "librustlibs[RUSTLIBS_SUFFIX].so"
else
// First check if it's built in the usual place.
if(fexists("./rust/target/i686-pc-windows-msvc/release/rustlibs.dll"))
return __rustlib = "./rust/target/i686-pc-windows-msvc/release/rustlibs.dll"
if(fexists("./rust/target/i686-pc-windows-msvc/release/rustlibs[RUSTLIBS_SUFFIX].dll"))
return __rustlib = "./rust/target/i686-pc-windows-msvc/release/rustlibs[RUSTLIBS_SUFFIX].dll"
// Then check in the current directory.
if(fexists("./rustlibs.dll"))
return __rustlib = "./rustlibs.dll"
if(fexists("./rustlibs[RUSTLIBS_SUFFIX].dll"))
return __rustlib = "./rustlibs[RUSTLIBS_SUFFIX].dll"

// And elsewhere.
return __rustlib = "rustlibs.dll"
var/assignment_confirmed = (__rustlib = "rustlibs[RUSTLIBS_SUFFIX].dll")
// This being spanned over multiple lines is kinda scuffed, but its needed because of https://www.byond.com/forum/post/2072419
return assignment_confirmed


#define RUSTLIB (__rustlib || __detect_rustlib())

#define RUSTLIB_CALL(func, args...) call_ext(RUSTLIB, "byond:[#func]_ffi")(args)

// This needs to go BELOW the above define, otherwise the BYOND compiler can make the above immediate call disappear
#undef RUSTLIBS_SUFFIX

/proc/milla_init_z(z)
return RUSTLIB_CALL(milla_initialize, z)

Expand Down
5 changes: 5 additions & 0 deletions code/datums/revision.dm
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ GLOBAL_PROTECT(revision_info) // Dont mess with this
msg += "<span class='notice'><b>Server Revision Info</b></span>"
// Round ID first
msg += "<b>Round ID:</b> [GLOB.round_id ? GLOB.round_id : "NULL"]"
#ifdef PARADISE_PRODUCTION_HARDWARE
msg += "<b>Production-hardware specific compile:</b> Yes"
#else
msg += "<b>Production-hardware specific compile:</b> No"
#endif

// Commit info
if(GLOB.revision_info.commit_hash && GLOB.revision_info.commit_date && GLOB.configuration.url.github_url)
Expand Down
Binary file modified rustlibs.dll
Binary file not shown.
Binary file added rustlibs_prod.dll
Binary file not shown.
Binary file modified tools/ci/librustlibs_ci.so
Binary file not shown.

0 comments on commit e154414

Please sign in to comment.