Giter Club home page Giter Club logo

Comments (5)

weissi avatar weissi commented on June 28, 2024 1

I think String is better than StaticString, it should in fact be faster.

  • String is exactly 2 words wide, StaticString is 2 words + 1 byte wide (I know, a mistake that's now unfixable with ABI). So passing a StaticString knocks out 3 registers, String only 2
  • String is more powerful than StaticString
  • String also has an "immortal" representation. So if you create a String that is in fact a static string, it won't allocate and its pointer will go straight into the data section.

@ShivaHuang I would suggest that everybody switch to String instead of StaticString. But do you have a concrete logging backend in mind where you'd need to pass file as a StaticString?

from swift-log.

ShivaHuang avatar ShivaHuang commented on June 28, 2024 1

I'll close this issue.

Thank you @ktoso and @weissi, I learned a lot in this discussion.

from swift-log.

ktoso avatar ktoso commented on June 28, 2024

I believe @weissi explored this topic in great depth with specific focus on OSLog so he should be able to answer best here.

from swift-log.

ShivaHuang avatar ShivaHuang commented on June 28, 2024

Great point!

I misunderstood the performance and memory usage between String and StaticString. And I agree that String is overall more suitable than StaticString.

The logging backend use StaticString I encounter is CocoaLumberjack.

However, after digging into their code, they also convert the StaticString to String before passing it to the underlay OC code. here
I think I should submit a PR to CocoaLumberjack for that. ๐Ÿ˜‰

BTW, while searching some similar use case in Apple's SDK, I found some functions use StaticString for the same propose. like

  • XCTAssertEqual from XCTest
  • assertionFailure(_:file:line:) from Swift Standard Library

Will Apple also change their code? ๐Ÿคฃ

from swift-log.

weissi avatar weissi commented on June 28, 2024

@ShivaHuang until Swift 4.2, StaticString was much faster which is why XCTAssertEqual was designed the way it is. Same for assertionFailure etc, now they canโ€™t easily change that because of source/ABI compat.

Also: StaticString should just be 1 word, thereโ€™s no reason except that nobody noticed until the ABI was fixed ๐Ÿ˜ฌ

from swift-log.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.