GNU social JP
  • FAQ
  • Login
GNU social JPは日本のGNU socialサーバーです。
Usage/ToS/admin/test/Pleroma FE
  • Public

    • Public
    • Network
    • Groups
    • Featured
    • Popular
    • People

Conversation

Notices

  1. Embed this notice
    David Smith (catfish_man@mastodon.social)'s status on Saturday, 22-Nov-2025 08:41:51 JST David Smith David Smith

    One little thing I love is how Swift helps with my favorite game*: the floor^W^Wmalloc is lava

    Allocation counts:

    ```
    NSMutableArray *c = [NSMutableArray array]; //1
    [c addObject: @"hello"]; //2
    id d = [c mutableCopy]; //3

    var a = [] //0
    a.append("hello") //1
    let b = a //1

    NSMutableString *e = [[NSMutableString alloc] init]; //1
    [e appendString: @"hello"]; //2
    id f = [e copy]; //3

    var g = "" //0
    g.append("hello") //0
    let h = g //0
    ```

    *"malloc is lava" is a survival horror roguelike

    In conversation about 8 months ago from mastodon.social permalink
    • Embed this notice
      Paul Cantrell (inthehands@hachyderm.io)'s status on Saturday, 22-Nov-2025 08:41:51 JST Paul Cantrell Paul Cantrell
      in reply to

      @Catfish_Man This one…!!

      ```
      var g = "" //0
      g.append("hello") //0
      let h = g //0
      ```

      At a guess:

      - “” and “hello” are both emitted in the binary, so no alloc?
      - And compiler knows that “”.append(foo) to empty can just simplify to foo?
      - …because…inlining? special case magic? something else?

      In conversation about 8 months ago permalink
    • Embed this notice
      David Smith (catfish_man@mastodon.social)'s status on Saturday, 22-Nov-2025 08:46:29 JST David Smith David Smith
      in reply to
      • Paul Cantrell

      @inthehands actually that one works two different ways 😂

      1) the smol Strings optimization means we *never* have to allocate for <= 15 bytes of UTF8

      2) appending to an empty String will indeed just return the argument (special case in the code), which is a constant in the binary

      …or possibly the argument is also smol, I forget how we emit that. It works either way here.

      In conversation about 8 months ago permalink
    • Embed this notice
      Paul Cantrell (inthehands@hachyderm.io)'s status on Saturday, 22-Nov-2025 08:46:29 JST Paul Cantrell Paul Cantrell
      in reply to

      @Catfish_Man
      Oh, did not know about the smol strings! Makes tons of sense. I take it the standard string struct is 16 bytes, and one byte is smol flag and/or len…?

      (I have never actually looked directly at Swift’s memory representation of anything!)

      In conversation about 8 months ago permalink
    • Embed this notice
      David Smith (catfish_man@mastodon.social)'s status on Saturday, 22-Nov-2025 08:52:09 JST David Smith David Smith
      in reply to
      • Paul Cantrell

      @inthehands yup. String being two words has other interesting consequences (like making collections of NSStrings change size as they bridge, which is awkward), but overall I'm quite happy with it.

      Another fun fact: when not in smol form, the pointed-to buffer is actually an NSString subclass, which allows us to implement String -> NSString bridging by just retaining and returning it.

      "But David, isn't Swift below Foundation? How can it subclass a Foundation class"

      class_setSuperclass 🫠

      In conversation about 8 months ago permalink
    • Embed this notice
      Paul Cantrell (inthehands@hachyderm.io)'s status on Saturday, 22-Nov-2025 08:52:09 JST Paul Cantrell Paul Cantrell
      in reply to

      @Catfish_Man > ”But David, isn't Swift below Foundation? How can it subclass a Foundation class"
      >class_setSuperclass 🫠

      Well there goes my youthful innocence

      In conversation about 8 months ago permalink
    • Embed this notice
      Paul Cantrell (inthehands@hachyderm.io)'s status on Saturday, 22-Nov-2025 08:54:42 JST Paul Cantrell Paul Cantrell
      in reply to

      @Catfish_Man
      “weak”?!

      As in “if this class is undefined, we no longer have a superclass?”

      In conversation about 8 months ago permalink
    • Embed this notice
      David Smith (catfish_man@mastodon.social)'s status on Saturday, 22-Nov-2025 08:54:43 JST David Smith David Smith
      in reply to
      • Paul Cantrell

      @inthehands I have a feature request in with the linker folks for "weak lazy subclassing", but they understandably are not thrilled with catering to my unhinged whims :D

      In conversation about 8 months ago permalink
    • Embed this notice
      Paul Cantrell (inthehands@hachyderm.io)'s status on Saturday, 22-Nov-2025 09:07:25 JST Paul Cantrell Paul Cantrell
      in reply to
      • I Can't Believe It's Not Zero!

      @Catfish_Man @steve
      “This is fi  ne”

      In conversation about 8 months ago permalink
    • Embed this notice
      David Smith (catfish_man@mastodon.social)'s status on Saturday, 22-Nov-2025 09:07:26 JST David Smith David Smith
      in reply to
      • Paul Cantrell
      • I Can't Believe It's Not Zero!

      @steve @inthehands it's like an onion where every layer is made of infuriating consequences

      In conversation about 8 months ago permalink
    • Embed this notice
      I Can't Believe It's Not Zero! (steve@discuss.systems)'s status on Saturday, 22-Nov-2025 09:07:27 JST I Can't Believe It's Not Zero! I Can't Believe It's Not Zero!
      in reply to
      • Paul Cantrell

      @inthehands @Catfish_Man I’m going to be angry about the 0124567xx89 32b layout for a long time.

      In conversation about 8 months ago permalink
    • Embed this notice
      I Can't Believe It's Not Zero! (steve@discuss.systems)'s status on Saturday, 22-Nov-2025 09:07:28 JST I Can't Believe It's Not Zero! I Can't Believe It's Not Zero!
      in reply to
      • Paul Cantrell

      @inthehands @Catfish_Man well, on 64b Apple platforms. On 32b they’re 12B (holding 8 utf8 units, or 10 but non-contiguous if code was built with an older Swift version and inlined), and on Android 64b they hold 14 instead of 15 utf8 units because of memory coloring. There may be other platform-specific oddities I’m forgetting.

      In conversation about 8 months ago permalink
    • Embed this notice
      Paul Cantrell (inthehands@hachyderm.io)'s status on Saturday, 22-Nov-2025 09:15:43 JST Paul Cantrell Paul Cantrell
      in reply to

      @Catfish_Man Ha! This code made me angry when I finally understood it.

      In conversation about 8 months ago permalink
    • Embed this notice
      David Smith (catfish_man@mastodon.social)'s status on Saturday, 22-Nov-2025 09:15:44 JST David Smith David Smith
      in reply to
      • Paul Cantrell

      @inthehands found the code I was thinking of that handles NSString * being half the size of String in collections while still avoiding a temporary buffer: https://github.com/swiftlang/swift-corelibs-foundation/blob/1b514e4242526690c19fad9f53644065dd50b69d/Darwin/Foundation-swiftoverlay/NSDictionary.swift#L102

      In conversation about 8 months ago permalink

      Attachments

      1. Domain not in remote thumbnail source whitelist: opengraph.githubassets.com
        swift-corelibs-foundation/Darwin/Foundation-swiftoverlay/NSDictionary.swift at 1b514e4242526690c19fad9f53644065dd50b69d · swiftlang/swift-corelibs-foundation
        The Foundation Project, providing core utilities, internationalization, and OS independence - swiftlang/swift-corelibs-foundation
    • Embed this notice
      Paul Cantrell (inthehands@hachyderm.io)'s status on Saturday, 22-Nov-2025 09:24:01 JST Paul Cantrell Paul Cantrell
      in reply to

      @Catfish_Man
      This bit…!

      https://github.com/swiftlang/swift-corelibs-foundation/blob/1b514e4242526690c19fad9f53644065dd50b69d/Darwin/Foundation-swiftoverlay/NSDictionary.swift#L130-L132

      “I’m sure those values didn’t need converting anyway”

      In conversation about 8 months ago permalink

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.