home.social

#xcodeinstruments — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #xcodeinstruments, aggregated by home.social.

  1. My friend and I are doing a presentation on #WASM. Part of it is taking a program (a sudoku solver) written by a friend (who, for this implementation, used #GeminiAI). The plan was for my friend to re-write it in #C, which can be compiled to WASM; and for me to write it in #RustLang, which also can be compiled to WASM. To keep the programs the same we couldn't optimize the actual algorithms, but we could optimize anything else. So, for instance, no making a linked list of empty spaces; but inlining cell lookup is fine. #Optimization

    On my machine, my initial implementation (again, in Rust), was 50% slower than his implementation in C (running over the same puzzle a million iterations).

    I started to optimize using #XcodeInstruments. My first time with this tool. Just didn't understand it well enough. I tried many optimizations: a one-dimensional array backing the board instead of an array of arrays; inlining particular functions; finding places where I knew it couldn't fail and removing checks. Things like that. Sure, I made it a little faster.

    Then listening to #RustaceanStation I learned of a specific feature. A simple feature. In my code, I represented board cells with a simple enum, almost an exact copy of Option, but instead of None, it is Empty; instead of Some(x), Digit(x). The new feature is NonZero. Option<u8> in Rust is two bytes. Option<NonZero<u8>> is one byte (because the u8 can't be 0, Rust can use the 0 value to mean None)!

    I applied exactly that one change to my implementation and that optimization, all by itself, made my program faster than his C implementation.

    I was completely surprised, and very pleasantly.

  2. Xcode Instruments saves the day! 🔨

    While doing some performance improvements on #Lysten I noticed that there was a mysterious peak in memory usage. This peak made the app crash due to consuming too much memory 💥😭

    Decided to try Xcode Instruments with the Allocations template, which could tell me that the perpetrator was Core Spotlight!

    @angelicaaa You inspired me to use Instruments, kudos!

    #xcode #xcodeInstruments