Skip to content

Instantly share code, notes, and snippets.

View miguelraz's full-sized avatar
:shipit:

Miguel Raz Guzmán Macedo miguelraz

:shipit:
  • UNAM
  • UNAM, Mexico
View GitHub Profile

Cheatsheet for Julians

Why Learning Rust for Julia people in particular is special:

  • We already have many features that aren't a new sale: safety and performance through a fast GC, standard memory semantics that have mechanical sympathy coupled with a powerful JIT, a modern package manager, a unit testing framework, metaprogramming, and a documentation system.
  • When reaching for Rust is justified (resource constrained environments like embedded, cloud infrastructure or data bases, etc.) Julians have to go straight for FFI, erasing many of the boons of Safe Rust and dealing very quickly with unsafe code. This is topic is not the promising experience for beginners in the language.
  • Julians are used to thinking about memory footprint and layout in perf-sensitive code, as well as subtyping relations - two lynchpins for understanding the ownership and borrowsing system where the role of subtyping and variance are very commonly ommitted. This topic can therefore be explained much clearer and earlie
@miguelraz
miguelraz / perfnotesrust.md
Created February 29, 2024 16:34
perf notes for Rust

Rust Speed Optimizations

From setting core_affinity to measuring L1i cache misses with good ol' perf or poking at hardware counters, if there's standard perf tooling you expect to work, it should work well in Rust too (but it might look a bit different than what you expect.)

The Rust community has a healthy suite of monitoring for hundreds of perf mentrics, see perf.rust-lang.org.

Let's look at some Rust specific flavors of what you should know.

Prior training material art

mrg@LAPTOP-F1SH43QJ:~$ dust .
1.2G ┌── stable-x86_64-unknown-linux-gnu │ █████ │ 6%
1.2G ┌─┴ toolchains │ █████ │ 6%
1.2G ┌─┴ .rustup │ █████ │ 6%
1.6G │ ┌── index.crates.io-6f17d22bba15001f│ ░▒██████ │ 8%
1.6G │ ┌─┴ src │ ░▒██████ │ 8%
1.8G │ ┌─┴ registry │ ░███████ │ 9%
2.0G ├─┴ .cargo │ ████████ │ 10%
863M │ ┌── stage0-std │
I[23:39:28.282] clangd version 16.0.2 (https://github.com/llvm/llvm-project 18ddebe1a1a9bde349441631365f0472e9693520)
I[23:39:28.283] Features: windows+grpc
I[23:39:28.283] PID: 23980
I[23:39:28.283] Working directory: \\wsl.localhost\Ubuntu\home\mrg\llvm-project
I[23:39:28.283] argv[0]: c:\Users\mrg\AppData\Roaming\Code\User\globalStorage\llvm-vs-code-extensions.vscode-clangd\install\16.0.2\clangd_16.0.2\bin\clangd.exe
I[23:39:28.283] argv[1]: --clang-tidy
I[23:39:28.283] argv[2]: --compile-commands-dir=\\wsl.localhost\Ubuntu\home\mrg\llvm-project\build
I[23:39:28.295] Starting LSP over stdin/stdout
I[23:39:28.296] <-- initialize(0)
I[23:39:28.363] --> reply:initialize(0) 67 ms
This file has been truncated, but you can view the full file.
[I] mrg@pop-os ~/o/LoopModels (bumprealloc) [1]> UBSAN_OPTIONS='print_stacktrace=1' cmake --build buildgcc/test
[0/2] Re-checking globbed directories...
[1/11] Clearing out old coverage data.
[2/11] Building CXX object CMakeFiles/LoopModelsTests.dir/graph_test.cpp.o
FAILED: CMakeFiles/LoopModelsTests.dir/graph_test.cpp.o
/home/mrg/opt/GNAT/2021/bin/g++ -I/home/mrg/oss/LoopModels/test/../include -I/usr/lib/llvm-15/include -I/home/mrg/oss/LoopModels/buildgcc/test/_deps/unordered_dense-src/include -isystem /home/mrg/oss/LoopModels/buildgcc/test/_deps/googletest-src/googletest/include -isystem /home/mrg/oss/LoopModels/buildgcc/test/_deps/googletest-src/googletest -fno-omit-frame-pointer -fsanitize=address,undefined -g -fno-exceptions -fno-omit-frame-pointer -fmax-errors=8 -fconcepts-diagnostics-depth=4 -fno-semantic-interposition -fdiagnostics-color=always -Wall -Wpedantic -Wextra -Wshadow -D_GLIBCXX_ASSERTIONS -O0 -g --coverage -std=gnu++2a -Winvalid-pch -include /home/mrg/oss/LoopModels/buildgcc/test/CMakeFil
cmake -G Ninja -DLLVM_TARGETS_TO_BUILD="X86" \
-DCMAKE_BUILD_TYPE="Debug" \
-DBUILD_SHARED_LIBS=ON \
-DLLVM_USE_SPLIT_DWARF=OFF \
-DLLVM_USE_LINKER=lld \
-DLLVM_OPTIMIZED_TABLEGEN=ON \
-DCMAKE_C_COMPILER="/usr/lib/ccache/clang" \
-DLLVM_PARALLEL_LINK_JOBS="8" \
-DLLVM_PARALLEL_COMPILE_JOBS="8" \
-DCMAKE_CXX_COMPILER="/usr/lib/ccache/clang++" \
julia> using GLMakie
[ Info: Precompiling GLMakie [e9467ef8-e4e7-5192-8a1a-b1aee30e663a]
libGL error: MESA-LOADER: failed to open radeonsi: /usr/lib/dri/radeonsi_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
libGL error: failed to load driver: radeonsi
libGL error: MESA-LOADER: failed to open radeonsi: /usr/lib/dri/radeonsi_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
libGL error: failed to load driver: radeonsi
libGL error: MESA-LOADER: failed to open swrast: /usr/lib/dri/swrast_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
libGL error: failed to load driver: swrast
┌ Warning: GLFW couldn't create an OpenGL window.
│ This likely means, you don't have an OpenGL capable Graphic Card,

Very rough sketch!

  1. way more mini exercises
  • loopy vs iterator way
  • factorial and add
    • 1 to 100 elems
  • collect all evens
  • any
  • all
  • fold, scan, reduce, flatten_map, tree_fold1
  • partition, partition_in_place, (COMPARE to C++)
https://github.com/miguelraz/JuliaParaGenteConPrisa
Codigo de laplace!
x + 1