<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Satoshi Konno</title>
    <description>The latest articles on Forem by Satoshi Konno (@cybergarage).</description>
    <link>https://forem.com/cybergarage</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1999005%2Fc830345a-723c-4fb1-b8f0-d7934c8e58d9.png</url>
      <title>Forem: Satoshi Konno</title>
      <link>https://forem.com/cybergarage</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/cybergarage"/>
    <language>en</language>
    <item>
      <title>Rust Implementation Guide - from efficient learning to implementation</title>
      <dc:creator>Satoshi Konno</dc:creator>
      <pubDate>Sun, 19 Jan 2025 08:53:26 +0000</pubDate>
      <link>https://forem.com/cybergarage/rust-implementation-guide-from-efficient-learning-to-implementation-2h38</link>
      <guid>https://forem.com/cybergarage/rust-implementation-guide-from-efficient-learning-to-implementation-2h38</guid>
      <description>&lt;p&gt;In the last issue &lt;a href="https://dev.to/cybergarage/rust-vs-go-vs-c-database-and-iot-application-performance-benchmarks-30h8"&gt;[30]&lt;/a&gt;, I implemented the same application in Go, Rust, and C (+ Python) and evaluated the implementation efficiency and speed with each language. In this article, we will summarize our views on how to learn and implement Rust efficiently based on our experience.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to learn Rust
&lt;/h1&gt;

&lt;p&gt;Rust is considered a language that requires a learning period before productivity is realized &lt;a href="https://blog.rust-lang.org/2020/04/17/Rust-survey-2019.html" rel="noopener noreferrer"&gt;[5]&lt;/a&gt;. With statistics showing that more than 50% of people leave during the initial learning phase and many of them fail within a month &lt;a href="https://blog.rust-lang.org/2018/11/27/Rust-survey-2018.html" rel="noopener noreferrer"&gt;[6]&lt;/a&gt;, effective initial learning is especially important.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP1: Overcoming the Learning Readiness Phase
&lt;/h2&gt;

&lt;p&gt;There are many esoteric interpretations of the Rust compiler (without explicit solutions) &lt;a href="https://www.amazon.co.jp/dp/4873119782" rel="noopener noreferrer"&gt;[11]&lt;/a&gt;, but first learn the basics of the Rust compiler until you understand and can interact with its error content.&lt;/p&gt;

&lt;p&gt;While Rust is rife with books and materials for beginners &lt;a href="https://blog.rust-lang.org/2020/04/17/Rust-survey-2019.html" rel="noopener noreferrer"&gt;[5]&lt;/a&gt;, there is a dearth of materials aimed at practical intermediate and above &lt;a href="https://blog.rust-lang.org/2020/04/17/Rust-survey-2019.html" rel="noopener noreferrer"&gt;[5]&lt;/a&gt; has not improved much. In conclusion, instead of struggling with compilers in the dark, the shortcut to Rust mastery is to first improve basic skills with good learning materials, which are the primary resources shown below &lt;a href="https://msrc.microsoft.com/blog/2019/10/an-interns-experience-with-rust/" rel="noopener noreferrer"&gt;[7]&lt;/a&gt;&lt;a href="https://zenn.dev/magurotuna/books/tokio-tutorial-ja/viewer/preface" rel="noopener noreferrer"&gt;[8]&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://doc.rust-lang.org/stable/book/" rel="noopener noreferrer"&gt;[1] The Rust Programming Language&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.co.jp/dp/4873119782" rel="noopener noreferrer"&gt;[2] Programming Rust 2nd Edition&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are also scattered opinions that C/C++ is easy for skilled users to learn &lt;a href="https://msrc.microsoft.com/blog/2019/10/an-interns-experience-with-rust/" rel="noopener noreferrer"&gt;[7]&lt;/a&gt;&lt;a href="https://msrc-blog.microsoft.com/2019/11/07/using-rust-in-windows/" rel="noopener noreferrer"&gt;[9]&lt;/a&gt;&lt;a href="https://www.youtube.com/watch?v=kylqq8pEgRs" rel="noopener noreferrer"&gt;[10]&lt;/a&gt;, so in terms of deepening the usefulness of Rust, it is also important to deepen the C/C ++ language may also be a shortcut to learning Rust.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP2: Practical project challenges
&lt;/h2&gt;

&lt;p&gt;If your goal is to "learn Rust," you will have achieved your objective at this stage. However, the difficulty of Rust lies in the difficulty of practice, after overcoming the preparatory phase of the learning curve &lt;a href="https://blog.rust-lang.org/2020/04/17/Rust-survey-2019.html" rel="noopener noreferrer"&gt;[5]&lt;/a&gt;&lt;a href="https://keens.github.io/blog/2019/04/21/jissenrustnyuumon_wokaitayo/" rel="noopener noreferrer"&gt;[11]&lt;/a&gt;&lt;a href="https://stackoverflow.com/questions/30681468/passing-mutable-self-reference-to-method-of-owned-object" rel="noopener noreferrer"&gt;[12]&lt;/a&gt;&lt;a href="https://rust-unofficial.github.io/too-many-lists/" rel="noopener noreferrer"&gt;[15]&lt;/a&gt;. In conclusion, it seems to be efficient for Rust learning to start some kind of practical project &lt;a href="https://blog.rust-lang.org/2022/02/15/Rust-Survey-2021.html" rel="noopener noreferrer"&gt;[13]&lt;/a&gt;&lt;a href="https://gihyo.jp/article/2022/09/rust-monthly-topics-01" rel="noopener noreferrer"&gt;[14]&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If it does not follow the semantics of Rust, design patterns (experience) in other programming languages cannot be brought in directly &lt;a href="https://rust-unofficial.github.io/patterns/" rel="noopener noreferrer"&gt;[16]&lt;/a&gt;, and trial and error is required. In terms of comparison with existing languages, the following tutorials may be helpful.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://rust-unofficial.github.io/too-many-lists/" rel="noopener noreferrer"&gt;[15] Learning Rust With Entirely Too Many Linked Lists&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As mentioned above, the situation &lt;a href="https://blog.rust-lang.org/2020/04/17/Rust-survey-2019.html" rel="noopener noreferrer"&gt;[5]&lt;/a&gt;, where there is a dearth of material aimed at the practical intermediate level and above, has not improved very much. As an actual example, you can read the divergence between the following materials recommended for beginners to step up and the practical subject matter &lt;a href="https://rust-unofficial.github.io/too-many-lists/" rel="noopener noreferrer"&gt;[15]&lt;/a&gt; shown in the above tutorial.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://doc.rust-lang.org/stable/rust-by-example/" rel="noopener noreferrer"&gt;[3] Rust By Example&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://rust-lang-nursery.github.io/rust-cookbook/" rel="noopener noreferrer"&gt;[17] Rust Cookbook&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In other words, because there is not as much "Effective" intermediate and above information as in other languages, you need to struggle with the Rust compiler and establish (pioneer) the following design patterns (experiences) &lt;a href="https://rust-unofficial.github.io/patterns/" rel="noopener noreferrer"&gt;[16]&lt;/a&gt; must be established (pioneered) by yourself while struggling with the Rust compiler.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://rust-unofficial.github.io/patterns/" rel="noopener noreferrer"&gt;[16] Rust Design Patterns&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/book/first-edition/README.html" rel="noopener noreferrer"&gt;[18] Effective Rust - The Rust Programming Language&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.lurklurk.org/effective-rust/" rel="noopener noreferrer"&gt;[19] Effective Rust&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://doc.rust-lang.org/1.30.0/book/2018-edition/index.html" rel="noopener noreferrer"&gt;[20] Effective Rust&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Many books and materials that are considered intermediate level are simplified by limiting the field of application, both in a good and bad way. In conclusion, there are few things better than official materials, and a practical shortcut may be to deepen understanding by trial and error while going back to official materials in practice.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://doc.rust-lang.org/stable/book/" rel="noopener noreferrer"&gt;[1] The Rust Programming Language&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.co.jp/dp/4873119782" rel="noopener noreferrer"&gt;[2] Programming Rust 2nd Edition&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Books that are field-specific in title are an effective way to gain implementation knowledge of Rust in a specific area, serving as a Rosetta Stone of sorts. However, it should be understood only as one implementation example, and whether it is the best way or not may be reconsidered through practice.&lt;/p&gt;

&lt;h1&gt;
  
  
  Rust at Work
&lt;/h1&gt;

&lt;p&gt;The most recent Rust community survey included a "Rust at Work" item &lt;a href="https://blog.rust-lang.org/2022/12/05/survey-launch.html" rel="noopener noreferrer"&gt;[21]&lt;/a&gt;&lt;a href="https://blog.rust-lang.org/2022/02/15/Rust-Survey-2021.html" rel="noopener noreferrer"&gt;[13]&lt;/a&gt;, which emphasizes the adoption of Rut as a professional language. The most recent, 2021 survey results &lt;a href="https://blog.rust-lang.org/2022/02/15/Rust-Survey-2021.html" rel="noopener noreferrer"&gt;[13]&lt;/a&gt; show that while the rate of use at work has increased significantly from 42% to 59% in the previous year, industry adoption The lack of adoption in the industry was cited as the biggest concern (38%) for Rust's future.&lt;/p&gt;

&lt;p&gt;Basically, a programming language is a means to an end and should be selected based on the circumstances of the target project and team. Based on this assumption, here is a list of items to consider when adopting Rust.&lt;/p&gt;

&lt;h2&gt;
  
  
  Consideration of project characteristics
&lt;/h2&gt;

&lt;p&gt;First, it is important to determine whether the project to which Rust is applied is compatible with Rust semantics, in the sense of avoiding implementation complexity and performance degradation in Rust. Simply put, a project that is not stateless and involves parallel processing with data sharing in the Rust processing unit cannot be handled solely with Rust's move (Move) semantics, and ownership and lifetime management will become more complex.&lt;/p&gt;

&lt;p&gt;For example, stateless web applications and&lt;a href="https://www.usenix.org/legacy/event/osdi04/tech/full_papers/dean/dean_html/" rel="noopener noreferrer"&gt;[31]&lt;/a&gt;, which can be handled naturally with Rust's move (Move) semantics and SEDA&lt;a href="https://dl.acm.org/doi/abs/10.1145/502059.502057" rel="noopener noreferrer"&gt;[32]&lt;/a&gt;, which are concurrency models that do not require data sharing, the semantics of Rust adoption is unlikely to be a problem.&lt;/p&gt;

&lt;p&gt;Also, if we ignore the compatibility and complexity of the implementation, the adoption track record of Rust in the same field as the project, and for what applications and at what scale it has been implemented, will be a good guide for making an adoption decision &lt;a href="https://github.com/rust-unofficial/awesome-rust" rel="noopener noreferrer"&gt;[14]&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Secure core members
&lt;/h2&gt;

&lt;p&gt;What is clear is that if you are at a stage where you do not have personnel proficient in Rust, and you cannot determine the compatibility of Rust with the characteristics of your project, you should avoid hiring Rust. Simply put, you should avoid hiring Rust out of curiosity.&lt;/p&gt;

&lt;p&gt;It is essential to have a core team that is proficient in Rust. Conversely, if the core team has established design patterns for Rust implementation, it will be easier to add more people to the project, even if they are new to Rust.&lt;/p&gt;

&lt;p&gt;Basically, if core members have established a template or methodology for implementing Rust in a project, new members can follow that style and extend the project structure even if they are not necessarily proficient in Rust.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scope of Standard Library Offerings
&lt;/h2&gt;

&lt;p&gt;Rust is a language that has strengths in system programming and situations where high performance is required, but the coverage and functionality of the standard library is on the poor side, similar to the C language. The standard library provided lacks functionality and speed &lt;a href="https://dev.to/cybergarage/rust-vs-go-vs-c-database-and-iot-application-performance-benchmarks-30h8"&gt;[30]&lt;/a&gt;. memo/rust-eval-loc-perf/)&lt;a href="https://nnethercote.github.io/perf-book/" rel="noopener noreferrer"&gt;[30]&lt;/a&gt;&lt;a href="https://prev.rust-lang.org/faq.htm" rel="noopener noreferrer"&gt;[31]&lt;/a&gt;, and other maturity challenges In some cases, the&lt;/p&gt;

&lt;p&gt;Realistically, considering the scope of standard library offerings and the economics of the project, we will have to take the approach of developing a combination of third-party crates. In particular, for complex data structures and highly parallel processing functions, we are forced to rely heavily on third-party crates.&lt;/p&gt;

&lt;p&gt;However, depending on the quality and maintenance status of the crate, the project may be more at risk, and this should be taken into consideration. Also, as with Perl's CPAN, crates are registered on a first-come, first-served basis, so even if a crate is published under a major name, there may be alternative crates of higher quality and more actively developed, so thorough investigation is essential before adoption.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inheritance of past assets
&lt;/h2&gt;

&lt;p&gt;Realistically, many will want to leverage existing development assets rather than implement exclusively in Rust, and Rust continues to see a high demand for interoperability with C/C++ language assets as an important issue &lt;a href="https://blog.rust-lang.org/2020/04/17/Rust-survey-2019.html" rel="noopener noreferrer"&gt;[5]&lt;/a&gt;&lt;a href="https://atmarkit.itmedia.co.jp/ait/articles/1907/24/news130.html" rel="noopener noreferrer"&gt;[24]&lt;/a&gt;&lt;a href="https://msrc-blog.microsoft.com/2019/07/22/why-rust-for-safe-systems-programming/" rel="noopener noreferrer"&gt;[25]&lt;/a&gt;&lt;a href="https://blog.rust-lang.org/2020/12/16/rust-survey-2020.html" rel="noopener noreferrer"&gt;[26]&lt;/a&gt;&lt;a href="https://security.googleblog.com/2023/01/supporting-use-of-rust-in-chromium.html" rel="noopener noreferrer"&gt;[27]&lt;/a&gt;&lt;a href="https://security.googleblog.com/2021/09/an-update-on-memory-safety-in-chrome.html" rel="noopener noreferrer"&gt;[28]&lt;/a&gt;&lt;a href="https://www.chromium.org/Home/chromium-security/memory-safety/rust-and-c-interoperability/" rel="noopener noreferrer"&gt;[29]&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Compared to C++, Objective-C, and Go, where interoperability with C is guaranteed at the language level and can be used simply by including header files, Rust's interoperability is one major barrier. Rust provides a FFI (Foreign Function Interface) to interface with other languages, but interoperation with C requires a separate FFI definition that shows the correspondence with Rust types. rust-bindgen&lt;a href="https://security.googleblog.com/2023/01/supporting-use-of-rust-in-chromium.html" rel="noopener noreferrer"&gt;[27]&lt;/a&gt;, but there are also FFI generators such as &lt;a href="https://security.googleblog.com/2021/09/an-update-on-memory-safety-in-chrome.html" rel="noopener noreferrer"&gt;[28]&lt;/a&gt;&lt;a href="https://www.chromium.org/Home/chromium-security/memory-safety/rust-and-c-interoperability/" rel="noopener noreferrer"&gt;[29]&lt;/a&gt; will be an important factor in the decision to adopt Rust.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;While Rust is highly secure and performs well, learning Rust involves steep hurdles and struggles with the compiler, so effective learning methods and preparation are necessary. In the initial stages, it is important to cultivate a basic ability to understand and respond to compiler error messages, and to ensure that you learn Rust-specific concepts by using good official materials and books for beginning students.&lt;/p&gt;

&lt;p&gt;When considering the adoption of Rust for a project, it is particularly important to confirm the project characteristics and the Rust proficiency of the team, and to establish appropriate design patterns and support systems.&lt;/p&gt;

&lt;p&gt;We hope that by utilizing the learning materials and reference materials introduced in this article, you will be able to maximize the potential of Rust by establishing basic skills and then putting them into practice.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://doc.rust-lang.org/stable/book/" rel="noopener noreferrer"&gt;[1] The Rust Programming Language&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.co.jp/dp/4873119782" rel="noopener noreferrer"&gt;[2] Programming Rust 第2版&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.rust-lang.org/2022/02/15/Rust-Survey-2021.html" rel="noopener noreferrer"&gt;[3] Rust Survey 2021 Results | Rust Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.rust-lang.org/2020/12/16/rust-survey-2020.html" rel="noopener noreferrer"&gt;[4] Rust Survey 2020 Results | Rust Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.rust-lang.org/2020/04/17/Rust-survey-2019.html" rel="noopener noreferrer"&gt;[5] Rust Survey 2019 Results | Rust Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.rust-lang.org/2018/11/27/Rust-survey-2018.html" rel="noopener noreferrer"&gt;[6] Rust Survey 2018 Results | Rust Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gihyo.jp/article/2022/09/rust-monthly-topics-01" rel="noopener noreferrer"&gt;[7] データでわかるRustの開発者達 〜Rust Survey 2021の深堀 | gihyo.jp&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.rust-lang.org/2022/12/05/survey-launch.html" rel="noopener noreferrer"&gt;[8] Launching the 2022 State of Rust Survey | Rust Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[9] ECHONET Lite規格書 | ECHONET&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[10] Machine Readable Appendix Release | ECHONET&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/uecho" rel="noopener noreferrer"&gt;[11] uEcho for C&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/uecho-rs" rel="noopener noreferrer"&gt;[12] uEcho for Rust&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/uecho-go" rel="noopener noreferrer"&gt;[13] uEcho for Go&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/uecho-py" rel="noopener noreferrer"&gt;[14] uEcho for Pyton&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/uecho-bench" rel="noopener noreferrer"&gt;[15] Benchmark utility package for uEcho implementations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/XAMPPRocky/tokei" rel="noopener noreferrer"&gt;[16] Tokei (時計)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nnethercote.github.io/perf-book/" rel="noopener noreferrer"&gt;[17] The Rust Performance Book&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://prev.rust-lang.org/faq.htm" rel="noopener noreferrer"&gt;[18] The Rust Language FAQ&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://redis.io" rel="noopener noreferrer"&gt;[19] Redis&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tokio.rs/" rel="noopener noreferrer"&gt;[20] Tokio - An asynchronous Rust runtime&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/tokio-rs/mini-redis" rel="noopener noreferrer"&gt;[21] tokio-rs/mini-redis: Incomplete Redis client and server implementation using Tokio - for learning purposes only&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/tokio-rs/mini-redis/issues/1" rel="noopener noreferrer"&gt;[22] Initial benchmark results · Issue #1 · tokio-rs/mini-redis · GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/go-redis" rel="noopener noreferrer"&gt;[23] cybergarage/go-redis: The go-redis is a database framework for implementing a Redis compatible server using Go easily.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.infoq.com/jp/news/2020/02/ibm-stop-work-swift-server/" rel="noopener noreferrer"&gt;[23] IBMがSwift開発を終了 - Chris Bailey氏とのQ&amp;amp;A&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://rust-unofficial.github.io/patterns/" rel="noopener noreferrer"&gt;[24] Rust Design Patterns&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://atmarkit.itmedia.co.jp/ait/articles/1907/24/news130.html" rel="noopener noreferrer"&gt;[25] Microsoftが「Rust」言語を導入、安全性以外の理由あり（続報）：性能や安全性以外にも評価あり - ＠IT&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://msrc-blog.microsoft.com/2019/07/22/why-rust-for-safe-systems-programming/" rel="noopener noreferrer"&gt;[26] Why Rust for safe systems programming – Microsoft Security Response Center&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://security.googleblog.com/2023/01/supporting-use-of-rust-in-chromium.html" rel="noopener noreferrer"&gt;[27] Google Online Security Blog: Supporting the Use of Rust in the Chromium Project&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://security.googleblog.com/2021/09/an-update-on-memory-safety-in-chrome.html" rel="noopener noreferrer"&gt;[28] Google Online Security Blog: An update on Memory Safety in Chrome&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.chromium.org/Home/chromium-security/memory-safety/rust-and-c-interoperability/" rel="noopener noreferrer"&gt;[29] Rust and C++ interoperability&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/cybergarage/rust-vs-go-vs-c-database-and-iot-application-performance-benchmarks-30h8"&gt;[30] Rust vs Go vs C: Database and IoT Application Performance Benchmarks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.usenix.org/legacy/event/osdi04/tech/full_papers/dean/dean_html/" rel="noopener noreferrer"&gt;[31] MapReduce: Simplified Data Processing on Large Clusters&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dl.acm.org/doi/abs/10.1145/502059.502057" rel="noopener noreferrer"&gt;[32] SEDA: an architecture for well-conditioned, scalable internet services
&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>rust</category>
    </item>
    <item>
      <title>Rust vs Go vs C: Database and IoT Application Performance Benchmarks</title>
      <dc:creator>Satoshi Konno</dc:creator>
      <pubDate>Sun, 19 Jan 2025 08:46:03 +0000</pubDate>
      <link>https://forem.com/cybergarage/rust-vs-go-vs-c-database-and-iot-application-performance-benchmarks-30h8</link>
      <guid>https://forem.com/cybergarage/rust-vs-go-vs-c-database-and-iot-application-performance-benchmarks-30h8</guid>
      <description>&lt;p&gt;Rust is a language designed to be both secure and fast &lt;a href="https://doc.rust-lang.org/stable/book/" rel="noopener noreferrer"&gt;[1]&lt;/a&gt;, and in recent years, it has been expected to make further strides as a professional language employed in business &lt;a href="https://blog.rust-lang.org/2022/02/15/Rust-Survey-2021.html" rel="noopener noreferrer"&gt;[3]&lt;/a&gt; &lt;a href="https://blog.rust-lang.org/2022/12/05/survey-launch.html" rel="noopener noreferrer"&gt;[8]&lt;/a&gt;. However, the results of the 2021 survey &lt;a href="https://blog.rust-lang.org/2022/02/15/Rust-Survey-2021.html" rel="noopener noreferrer"&gt;[3]&lt;/a&gt; also show that while the rate of use at work has increased significantly from 42% to 59%, the lack of actual adoption in the industry was cited as the biggest concern (38%) about Rust's future. &lt;/p&gt;

&lt;p&gt;In this article, to determine the practicality of Rust, we sought to compare and evaluate its implementation against application implementations with the same specifications in other programming languages, such as C and Go. We prepared two targeted evaluation applications, Database (Redis) and IoT (ECHONET Lite), to assess the efficiency and performance of practical Rust implementation.&lt;/p&gt;

&lt;p&gt;In summary, Go is considered the best successor to C from a Better C perspective, followed by Objective-C, Rust, and C++. Rust offers safety and speed but has limitations in productivity, interoperability, and programming flexibility. Despite these challenges, Go stands out for its implementation efficiency and stable performance, making it a safe choice for general-purpose applications.&lt;/p&gt;

&lt;h1&gt;
  
  
  Evaluation 1 - Database Application (Redis)
&lt;/h1&gt;

&lt;p&gt;This evaluation will compare C, Rust, and Go implementations of the Redis &lt;a href="https://redis.io" rel="noopener noreferrer"&gt;[19]&lt;/a&gt; specification in the database area as the same application. The official Redis implementation &lt;a href="https://redis.io" rel="noopener noreferrer"&gt;[19]&lt;/a&gt; is in C, while the Rust and Go implementations are unofficial subset implementations. The following is a list of databases using Redis used in this evaluation.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://redis.io" rel="noopener noreferrer"&gt;[19] Redis (Official Implementation&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/tokio-rs/mini-redis" rel="noopener noreferrer"&gt;[21] mini-redis (Unofficial Rust implementation)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/go-redis" rel="noopener noreferrer"&gt;[23] go-redis (Unofficial Rust implementation)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Rust implementation is mini-redis &lt;a href="https://github.com/tokio-rs/mini-redis" rel="noopener noreferrer"&gt;[21]&lt;/a&gt;, which was released as a learning tool for the Tokio &lt;a href="https://tokio.rs/" rel="noopener noreferrer"&gt;[20]&lt;/a&gt; library, and the Go implementation is a sample implementation (go-redis-server) of my Redis-compatible database implementation go-redis &lt;a href="https://github.com/cybergarage/go-redis" rel="noopener noreferrer"&gt;[23]&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Compared to the official Redis implementation &lt;a href="https://redis.io" rel="noopener noreferrer"&gt;[19]&lt;/a&gt;, mini-redis &lt;a href="https://github.com/tokio-rs/mini-redis" rel="noopener noreferrer"&gt;[21]&lt;/a&gt; and go-redis &lt;a href="https://github.com/cybergarage/go-redis" rel="noopener noreferrer"&gt;[23]&lt;/a&gt; are subset implementations, and therefore cannot be evaluated for implementation efficiency using LOC (Lines of Code), only for performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Evaluation Benchmarks
&lt;/h2&gt;

&lt;p&gt;The benchmark programs evaluated were performed with redis-benchmark, the official benchmark tool for Redis. The benchmarks are not a full set but are limited to SET/GET commands and are run every 10,000 iterations with the standard 50 threads.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuuxqiqp1utugk139m45q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuuxqiqp1utugk139m45q.png" width="800" height="219"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The reason for being limited to only basic SET/GET commands is that mini-redis &lt;a href="https://github.com/tokio-rs/mini-redis" rel="noopener noreferrer"&gt;[21]&lt;/a&gt; is only a minimal command implementation, such as SET/GET commands, and we followed the benchmark parameters &lt;a href="https://github.com/tokio-rs/mini-redis/issues/1" rel="noopener noreferrer"&gt;[22]&lt;/a&gt; in mini-redis &lt;a href="https://github.com/tokio-rs/mini-redis" rel="noopener noreferrer"&gt;[21]&lt;/a&gt;. Note that mini-redis &lt;a href="https://github.com/tokio-rs/mini-redis" rel="noopener noreferrer"&gt;[21]&lt;/a&gt; is the latest version at the time of evaluation and the environment is "Mac mini (2018) + macOS 12.6".&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance Evaluation - C &amp;gt; Go &amp;gt; Rust
&lt;/h2&gt;

&lt;p&gt;The results of the SET/GET command execution by "redis-benchmark" are shown below. The 99th percentile (p99(ratio)) value, which is used as an indicator for database operation, is shown at the right end of the table along with the performance ratio based on the C language.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feabukttfsxliegq35oku.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feabukttfsxliegq35oku.png" width="800" height="249"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the evaluation benchmarks, the official implementations of redis-server in C &lt;a href="https://redis.io" rel="noopener noreferrer"&gt;[19]&lt;/a&gt;, go-redis in Go &lt;a href="https://github.com/cybergarage/go-redis" rel="noopener noreferrer"&gt;[23]&lt;/a&gt;, and mini-redis in Rust &lt;a href="https://github.com/tokio-rs/mini-redis" rel="noopener noreferrer"&gt;[21]&lt;/a&gt; were faster, in that order. A graph of the above table is shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkcs2jop34b4v0yk7yxfs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkcs2jop34b4v0yk7yxfs.png" width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The C redis-server &lt;a href="https://redis.io" rel="noopener noreferrer"&gt;[19]&lt;/a&gt; was optimized and was about 3 times faster than the sample implementations in Go and Rust. Both Go's go-redis &lt;a href="https://github.com/cybergarage/go-redis" rel="noopener noreferrer"&gt;[23]&lt;/a&gt; and Rust's mini-redis &lt;a href="https://github.com/tokio-rs/mini-redis" rel="noopener noreferrer"&gt;[21]&lt;/a&gt; were implemented as samples, and both have room for improvement. Taking this into consideration, a brief review of the evaluation results for each programming language is presented below.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rust
&lt;/h3&gt;

&lt;p&gt;Compared to the official C redis-server &lt;a href="https://redis.io" rel="noopener noreferrer"&gt;[19]&lt;/a&gt;, SET: 28% and GET: 41% slower, and compared to the Go implementation go-redis &lt;a href="https://github.com/cybergarage/go-redis" rel="noopener noreferrer"&gt;[23]&lt;/a&gt;, SET: 78% (=2.879/3.663) and GET: 88% (=2.167/2.455) slower.&lt;/p&gt;

&lt;p&gt;Since the Tokio &lt;a href="https://tokio.rs/" rel="noopener noreferrer"&gt;[20]&lt;/a&gt; library has been released for training purposes, it is assumed that full-scale optimization has not yet been performed. However, to some extent, optimization seems to have been performed by comparing performance with the official implementation of Redis &lt;a href="https://redis.io" rel="noopener noreferrer"&gt;[19]&lt;/a&gt; &lt;a href="https://github.com/tokio-rs/mini-redis/issues/1" rel="noopener noreferrer"&gt;[22]&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It is positioned for learning the Tokio &lt;a href="https://tokio.rs/" rel="noopener noreferrer"&gt;[20]&lt;/a&gt; library, and the implementation basically uses the Tokio &lt;a href="https://tokio.rs/" rel="noopener noreferrer"&gt;[20]&lt;/a&gt; library, with the network part built based on the Tokio &lt;a href="https://tokio.rs/" rel="noopener noreferrer"&gt;[20]&lt;/a&gt; TCP server (tokio::net::TcpListener). However, the key-value data management part of the database is implemented with the HashMap of the standard (std) library and Mutex of the standard (std) library for exclusive control, as in the implementation of Evaluation 2. Performance issues may be based on performance issues of the standard (std) library &lt;a href="https://prev.rust-lang.org/faq.htm" rel="noopener noreferrer"&gt;[18]&lt;/a&gt;, such as HashMap &lt;a href="https://nnethercote.github.io/perf-book/" rel="noopener noreferrer"&gt;[17]&lt;/a&gt;, as in Evaluation 2.&lt;/p&gt;

&lt;h3&gt;
  
  
  Go
&lt;/h3&gt;

&lt;p&gt;Compared to the official C redis-server &lt;a href="https://redis.io" rel="noopener noreferrer"&gt;[19]&lt;/a&gt;, SET: 35% and GET: 46% faster, while compared to Rust's mini-redis &lt;a href="https://github.com/tokio-rs/mini-redis" rel="noopener noreferrer"&gt;[21]&lt;/a&gt;, SET: 127% (=3.663/2.879) and GET: 113% (=2.455/2.167) faster.&lt;/p&gt;

&lt;p&gt;Go-redis &lt;a href="https://github.com/cybergarage/go-redis" rel="noopener noreferrer"&gt;[23]&lt;/a&gt; is a framework for implementing Redis-compatible databases, and like mini-redis &lt;a href="https://github.com/tokio-rs/mini-redis" rel="noopener noreferrer"&gt;[21]&lt;/a&gt;, the target of this evaluation is a sample implementation, so the implementation is simple. The speed difference from the official implementation was unexpected due to the assumption that there was little room for optimization.&lt;/p&gt;

&lt;p&gt;Go-redis &lt;a href="https://github.com/cybergarage/go-redis" rel="noopener noreferrer"&gt;[23]&lt;/a&gt; and the sample implementation "go-redis-server" are implemented only with the standard library, and the key-value data management part of the database is implemented with sync.Map. It will be necessary to refer to the official implementation for performance differences with the official implementation, in parallel with identifying bottlenecks in the profiling.&lt;/p&gt;

&lt;h1&gt;
  
  
  Evaluation 2 - IoT Applications (ECHONET Lite)
&lt;/h1&gt;

&lt;p&gt;This evaluation targets client-server function implementations of ECHONET Lite &lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[9]&lt;/a&gt;, a communication protocol in the IoT field. This implementation is an evaluation of an application for which the target requirement specifications (= ECHONET Lite &lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[9]&lt;/a&gt; specifications) are the same, and the design and implementers are the same.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/uecho" rel="noopener noreferrer"&gt;[11] uecho (ECHONET Lite framework for C)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/uecho-rs" rel="noopener noreferrer"&gt;[12] uecho-rs (ECHONET Lite framework for Rust)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/uecho-go" rel="noopener noreferrer"&gt;[13] uecho-go (ECHONET Lite framework for Go)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/uecho-py" rel="noopener noreferrer"&gt;[14] uecho-py (ECHONET Lite framework for Python)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Evaluation Frameworks
&lt;/h2&gt;

&lt;p&gt;The Rust implementation &lt;a href="https://github.com/cybergarage/uecho-rs" rel="noopener noreferrer"&gt;[12]&lt;/a&gt; of ECHONET Lite &lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[9]&lt;/a&gt; implemented in C &lt;a href="https://github.com/cybergarage/uecho" rel="noopener noreferrer"&gt;[11]&lt;/a&gt;, Go &lt;a href="https://github.com/cybergarage/uecho-go" rel="noopener noreferrer"&gt;[13]&lt;/a&gt;, and Python &lt;a href="https://github.com/cybergarage/uecho-py" rel="noopener noreferrer"&gt;[14]&lt;/a&gt; are compared. The basic ECHONET Lite &lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[9]&lt;/a&gt; functions are implemented using the same design as far as possible, but there are some differences in function implementation between the languages. An overview of the differences in implemented functions is shown in the figure below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqkc8f32espch35oudhcb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqkc8f32espch35oudhcb.png" width="800" height="188"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The ECHONET Lite &lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[9]&lt;/a&gt; framework implementation subject to this evaluation was implemented in C, Go, Python, and Rust, in that order, and basically follows the same design.&lt;/p&gt;

&lt;p&gt;As explained in the ECHONET Lite &lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[9]&lt;/a&gt; Specification, the basic Device function, the Controller function for operating devices, and the Database function for standard devices &lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[10]&lt;/a&gt; defined in ECHONET Lite are implemented in all programming languages. &lt;/p&gt;

&lt;p&gt;However, for the transport layer of the ECHONET Lite &lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[9]&lt;/a&gt; specification, only the mandatory UDP communication function is implemented in all programming languages, while the optional TCP communicator is implemented only in C &lt;a href="https://github.com/cybergarage/uecho" rel="noopener noreferrer"&gt;[11]&lt;/a&gt; and Go &lt;a href="https://github.com/cybergarage/uecho-go" rel="noopener noreferrer"&gt;[13]&lt;/a&gt;, with implementation in Rust &lt;a href="https://github.com/cybergarage/uecho-rs" rel="noopener noreferrer"&gt;[12]&lt;/a&gt; and Python &lt;a href="https://github.com/cybergarage/uecho-py" rel="noopener noreferrer"&gt;[14]&lt;/a&gt; omitted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation Efficiency (≠ Effort) Evaluation - Python &amp;gt; Rust ≈ Go &amp;gt; C
&lt;/h2&gt;

&lt;p&gt;The efficiency of implementation in Rust was evaluated in terms of lines of code (LOC), which was calculated using Tokei &lt;a href="https://github.com/XAMPPRocky/tokei" rel="noopener noreferrer"&gt;[16]&lt;/a&gt; and excludes comments and blank lines. The results of LOC calculation are shown in the figure below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv9j6vvvgbjrjxg9o5je7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv9j6vvvgbjrjxg9o5je7.png" width="800" height="219"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For Auto, only the source code, which is the automatically generated code defining the ECHONET Lite standard devices &lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[10]&lt;/a&gt; and excluding the C language header file, was subject to evaluation. The graphs in the above table are shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5z8dqek027wgwldsdzcj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5z8dqek027wgwldsdzcj.png" width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Taking into account the range of implemented functionality, the LOC evaluation results in the following order: Python &amp;gt; Rust ≈ Go &amp;gt; C, with the least implemented code. Below is a brief review of each programming language.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rust
&lt;/h3&gt;

&lt;p&gt;The LOC results show that (although there is no implementation of TCP functionality), the implementation rating is equivalent to Go, with a LOC efficiency of 53% of that of C. This implementation with Rust was implemented using only standard (std) libraries such as Mutex, with the exception of the UDPSocket issue described below.&lt;/p&gt;

&lt;p&gt;Rust is a language that generally requires a learning period before it feels productive &lt;a href="https://blog.rust-lang.org/2020/04/17/Rust-survey-2019.html" rel="noopener noreferrer"&gt;[5]&lt;/a&gt;. Therefore, in Rust, it is not simply ‘less LOC = more implementation effort’: even code with a low LOC often takes a long time to implement because the developer struggles with the Rust compiler. Also, the extremely high LOC of auto-generated code is due to the specification of a standard maximum line width (max_width=100) in Rust's formatter (rustfmt), which is excluded from the evaluation.&lt;/p&gt;

&lt;p&gt;There are also restrictions due to Rust-specific move semantics and lifetime, which can make it impossible to bring in designs from other languages, which can lead to high design costs. In the current implementation, some design changes were made due to the limitations of introducing the Observer pattern for trait objects and the locking interval synchronised with the Mutex lifetime.&lt;/p&gt;

&lt;h3&gt;
  
  
  C
&lt;/h3&gt;

&lt;p&gt;The implementation in C resulted in the largest LOC. The reason for this is that this implementation does not use external libraries and includes self contained libraries (e.g. strings, list structures, object-oriented structures, etc.) which are not needed in other languages, and wrapper classes (e.g. Mutex, Thread, etc.) for portability. The home-grown libraries are shared with other C projects and are not as heavily implemented in this application as the LOC figures.&lt;/p&gt;

&lt;h3&gt;
  
  
  Go
&lt;/h3&gt;

&lt;p&gt;The LOC results show that the implementation efficiency is comparable to Rust, with an implementation rating of 63% of the source code compared to C. In Rust, there were issues with some of the standard libraries, but in the Go language, the implementation was carried out using only the standard libraries.&lt;/p&gt;

&lt;p&gt;Basically, the C design is implemented in the Go language as it is in C. Unlike the implementation in Rust, the design in C can be diverted and implemented, and there is flexibility. In addition, the standard library is more extensive than that of the C language, which can be evaluated as being directly related to ‘less LOC = less implementation time’.&lt;/p&gt;

&lt;h3&gt;
  
  
  Python
&lt;/h3&gt;

&lt;p&gt;The implementation in Python has the lowest LOC result in this implementation evaluation, because Python does not require parentheses ({}) in code block expressions, so a comparison with other languages that require parentheses (C, Rust, Go) requires a subtraction. Also, in comparison to Rust, the fact that implementations can be inherited contributes to the reduction of LOC.&lt;/p&gt;

&lt;p&gt;Python also has the flexibility to straightforwardly transfer designs from C and Go. Apart from the execution speed issues described below, it may be the best prototyping language&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance Evaluation - Go &amp;gt; C &amp;gt; Rust &amp;gt; Python
&lt;/h2&gt;

&lt;p&gt;The execution performance of Rust was evaluated for the same level of functionality of ECHONET Lite &lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[9]&lt;/a&gt;, the target of the evaluation, with the same basic design implementation. The benchmark program evaluated was a node in which the controller and objects of ECHONET Lite &lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[9]&lt;/a&gt; were implemented.&lt;/p&gt;

&lt;h3&gt;
  
  
  Evaluation Benchmarks
&lt;/h3&gt;

&lt;p&gt;In the benchmark program evaluated, the ECHONET Lite &lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[9]&lt;/a&gt; controller is a UDP client, and the object is a UDP server. The main loop, which is the basic sequence of the benchmark, consists of 12 UDP requests (Requests) from the controller and 12 UDP responses (Responses) from the object per execution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyy76jd84r0acz3dybpaq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyy76jd84r0acz3dybpaq.png" width="600" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To explain this in accordance with the ECHONET Lite &lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[9]&lt;/a&gt; Specification, the ECHONET Lite controller itself is discovered by a UDP multicast request (ESV: 0x62) and the implementation-required properties of the node profile object (0x0EF001) contained in the discovered controller node (0x0EF001) are set to the following values (12). The benchmark is 10,000 iterations of the request (ESV:0x62) response (ESV:0x72) operation with the UDP protocol for the values of &lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[10]&lt;/a&gt; (12 values). For the evaluation of implemented code, no optimization options were used in each environment. The environment is "Mac mini (2018) + macOS 12.6" and the details of the evaluation scripts are available here &lt;a href="https://github.com/cybergarage/uecho-bench" rel="noopener noreferrer"&gt;[15]&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Performance evaluation results
&lt;/h3&gt;

&lt;p&gt;The performance evaluation was measured by using the time command to measure the execution time of 10,000 iterations of the basic sequence shown in the evaluation benchmarks. The evaluation results are shown below, along with an overview of the compilation conditions and implementation techniques for each programming language.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5t3r6nnna9zshcyb6po3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5t3r6nnna9zshcyb6po3.png" width="800" height="165"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the evaluation benchmarks, Go was the fastest implementation, followed by C, Rust, and Python. Since UDP communication is asynchronous, data transmission and reception from a request (Request) to a response (Response) are implemented using the condition and channel mechanisms of each programming language. A graph of the above table is shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2k2hbqasv39xxyweeoj9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2k2hbqasv39xxyweeoj9.png" width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Python was excluded from the scalability analysis due to its extremely slow execution speed. In order to compare performance with C language, the performance ratio of each programming language relative to C language is shown in the figure below, along with a brief evaluation of the performance results for each programming language.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxv8g05chocn9j6w7qkfu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxv8g05chocn9j6w7qkfu.png" width="800" height="165"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Rust
&lt;/h4&gt;

&lt;p&gt;The Rust implementation performed worse than the Go and C implementations, being only 33% as fast as C and about 20% (=33/160) as fast as Go. While the system (sys) time is comparable to Go and faster than C, the user (user) time is larger than in C and Go.&lt;/p&gt;

&lt;p&gt;The cause needs to be investigated, but according to "The Rust Performance Book" &lt;a href="https://nnethercote.github.io/perf-book/" rel="noopener noreferrer"&gt;[17]&lt;/a&gt; and "The Rust Language FAQ" &lt;a href="https://prev.rust-lang.org/faq.htm" rel="noopener noreferrer"&gt;[18]&lt;/a&gt;, there are some standard (std) libraries, such as HashMap, that may be slow under certain circumstances.&lt;/p&gt;

&lt;p&gt;In addition, the standard (std) library Mutex, which is used extensively in this implementation, is difficult to handle because its valid interval is the same as that of the target object, and there are parts where copy semantics are unavoidably used to avoid this. Other language implementations are zero-copy (Zero Copy), so programmatically there is room for improvement (although significant design changes are required).&lt;/p&gt;

&lt;p&gt;In addition, the standard (std) library UDPSocket cannot support socket creation by the same port number, so a non-standard crate must be used in conjunction with the implementation of IoT-related protocols such as ECHONET Lite &lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[9]&lt;/a&gt; and mDNS, which are the target of this implementation. In addition, although IPv6 functionality has been implemented, it cannot be enabled at this time due to an error.&lt;/p&gt;

&lt;h4&gt;
  
  
  C
&lt;/h4&gt;

&lt;p&gt;Basically, the user (user) time is the fastest, but the system (sys) time is 2.5 times slower than Go and Rust. We had no concerns about the performance of the C language until this evaluation, but there may be issues with the use of standard libraries such as pthreads.&lt;/p&gt;

&lt;h4&gt;
  
  
  Go
&lt;/h4&gt;

&lt;p&gt;The Go implementation was the fastest in this evaluation benchmark, 1.6 times (=160%) faster than the C implementation and 5 times (=4.8=160%/33%) faster than the Rust implementation. It seems that the best results were obtained by writing a straightforward program.&lt;/p&gt;

&lt;h4&gt;
  
  
  Python
&lt;/h4&gt;

&lt;p&gt;As might be expected, the Python implementation produced the lowest results in this evaluation benchmark. The system (sys) time degraded by only 1/2 (=53%) compared to C, but the user (user) time performance is less than 1/100 (&amp;lt;1%), a characteristic of the interpreter execution since it is a pure Python implementation.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conslusion
&lt;/h1&gt;

&lt;p&gt;If I were to evaluate Go as the successor to C and from a Better C perspective, I would personally rank Go = (Objective-C) &amp;gt; Rust &amp;gt; C++. C++ is overspecified in terms of Better C, and Objective-C has stopped evolving since 2007 (2.0) when ARC was introduced. Swift, the supposed successor, also has an uncertain multi-platform future &lt;a href="https://github.com/cybergarage/go-redis" rel="noopener noreferrer"&gt;[23]&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Regarding productivity, Rust is a language that generally requires a learning period before it feels productive &lt;a href="https://blog.rust-lang.org/2020/04/17/Rust-survey-2019.html" rel="noopener noreferrer"&gt;[5]&lt;/a&gt;. It is a language that is both safe and fast &lt;a href="https://doc.rust-lang.org/stable/book/" rel="noopener noreferrer"&gt;[1]&lt;/a&gt;, but due to its limitations, it is a language that forces a struggle with the compiler, both good and bad. If it does not follow Rust's semantics, it is not possible to bring in design patterns (experience) from other languages. However, its limitations make it a language that requires contending with the compiler, in both good and bad ways.&lt;/p&gt;

&lt;p&gt;In terms of productivity, it is often desirable to use existing development assets rather than implementations that can be completed only in Rust, as in this evaluation. Interoperability of C/C++ language assets continues to be highly desired in Rust and is recognized as a major challenge &lt;a href="https://blog.rust-lang.org/2020/04/17/Rust-survey-2019.html" rel="noopener noreferrer"&gt;[5]&lt;/a&gt; &lt;a href="https://atmarkit.itmedia.co.jp/ait/articles/1907/24/news130.html" rel="noopener noreferrer"&gt;[25]&lt;/a&gt; &lt;a href="https://msrc-blog.microsoft.com/2019/07/22/why-rust-for-safe-systems-programming/" rel="noopener noreferrer"&gt;[26]&lt;/a&gt; &lt;a href="https://blog.rust-lang.org/2020/12/16/rust-survey-2020.html" rel="noopener noreferrer"&gt;[4]&lt;/a&gt; &lt;a href="https://security.googleblog.com/2023/01/supporting-use-of-rust-in-chromium.html" rel="noopener noreferrer"&gt;[27]&lt;/a&gt;. While there are FFI generators such as rust-bindgen &lt;a href="https://security.googleblog.com/2023/01/supporting-use-of-rust-in-chromium.html" rel="noopener noreferrer"&gt;[27]&lt;/a&gt;, they are not interoperable with existing assets, and the interoperability issue is a major barrier compared to C++, Objective-C, and Go, where interoperability with C is guaranteed at the language level and can be used simply by including header files. Interoperability issues will be a factor in the decision to adopt Rust.&lt;/p&gt;

&lt;p&gt;In terms of design, Rust also has to bring in reference (Arc) and exclusion control (Mutex) semantics similar to the C/C++/Go languages in concurrency applications (with data sharing), and also has to avoid the semantic limitations of Rust's language specification, such as move and lifetime. There is no escape from the limitations of the Rust language specification, such as Move and Lifetime. As a result, the degree of programming flexibility is limited compared to other programming languages, and design and implementation trade-off decisions need to be made that have an impact on productivity and performance, as shown in the performance evaluation discussion in Evaluation (ii).&lt;/p&gt;

&lt;p&gt;As for safety, Rust is a programming language that is ensured by static analysis and dynamic boundary checks. However, even in traditional C/C++, a wealth of static analysis tools (e.g. Clang Static Analyze) and dynamic analysis tools (e.g. Valgrind) can be utilised, so a comprehensive evaluation including peripheral tools will be necessary.&lt;/p&gt;

&lt;p&gt;Finally, in the performance evaluation, issues were identified in the Rust, C, and Go implementations. In this evaluation, the Go implementation showed good implementation efficiency and stable performance. Go may be the safest candidate as a general-purpose option. In any case, we will investigate the performance issues of each language in more detail.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://doc.rust-lang.org/stable/book/" rel="noopener noreferrer"&gt;[1] The Rust Programming Language&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.co.jp/dp/4873119782" rel="noopener noreferrer"&gt;[2] Programming Rust 第2版&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.rust-lang.org/2022/02/15/Rust-Survey-2021.html" rel="noopener noreferrer"&gt;[3] Rust Survey 2021 Results | Rust Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.rust-lang.org/2020/12/16/rust-survey-2020.html" rel="noopener noreferrer"&gt;[4] Rust Survey 2020 Results | Rust Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.rust-lang.org/2020/04/17/Rust-survey-2019.html" rel="noopener noreferrer"&gt;[5] Rust Survey 2019 Results | Rust Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.rust-lang.org/2018/11/27/Rust-survey-2018.html" rel="noopener noreferrer"&gt;[6] Rust Survey 2018 Results | Rust Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gihyo.jp/article/2022/09/rust-monthly-topics-01" rel="noopener noreferrer"&gt;[7] データでわかるRustの開発者達 〜Rust Survey 2021の深堀 | gihyo.jp&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.rust-lang.org/2022/12/05/survey-launch.html" rel="noopener noreferrer"&gt;[8] Launching the 2022 State of Rust Survey | Rust Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[9] ECHONET Lite規格書 | ECHONET&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://echonet.jp/spec_g/" rel="noopener noreferrer"&gt;[10] Machine Readable Appendix Release | ECHONET&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/uecho" rel="noopener noreferrer"&gt;[11] uEcho for C&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/uecho-rs" rel="noopener noreferrer"&gt;[12] uEcho for Rust&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/uecho-go" rel="noopener noreferrer"&gt;[13] uEcho for Go&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/uecho-py" rel="noopener noreferrer"&gt;[14] uEcho for Pyton&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/uecho-bench" rel="noopener noreferrer"&gt;[15] Benchmark utility package for uEcho implementations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/XAMPPRocky/tokei" rel="noopener noreferrer"&gt;[16] Tokei (時計)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nnethercote.github.io/perf-book/" rel="noopener noreferrer"&gt;[17] The Rust Performance Book&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://prev.rust-lang.org/faq.htm" rel="noopener noreferrer"&gt;[18] The Rust Language FAQ&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://redis.io" rel="noopener noreferrer"&gt;[19] Redis&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tokio.rs/" rel="noopener noreferrer"&gt;[20] Tokio - An asynchronous Rust runtime&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/tokio-rs/mini-redis" rel="noopener noreferrer"&gt;[21] tokio-rs/mini-redis: Incomplete Redis client and server implementation using Tokio - for learning purposes only&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/tokio-rs/mini-redis/issues/1" rel="noopener noreferrer"&gt;[22] Initial benchmark results · Issue #1 · tokio-rs/mini-redis · GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/cybergarage/go-redis" rel="noopener noreferrer"&gt;[23] cybergarage/go-redis: The go-redis is a database framework for implementing a Redis compatible server using Go easily.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.infoq.com/jp/news/2020/02/ibm-stop-work-swift-server/" rel="noopener noreferrer"&gt;[23] IBMがSwift開発を終了 - Chris Bailey氏とのQ&amp;amp;A&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://rust-unofficial.github.io/patterns/" rel="noopener noreferrer"&gt;[24] Rust Design Patterns&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://atmarkit.itmedia.co.jp/ait/articles/1907/24/news130.html" rel="noopener noreferrer"&gt;[25] Microsoftが「Rust」言語を導入、安全性以外の理由あり（続報）：性能や安全性以外にも評価あり - ＠IT&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://msrc-blog.microsoft.com/2019/07/22/why-rust-for-safe-systems-programming/" rel="noopener noreferrer"&gt;[26] Why Rust for safe systems programming – Microsoft Security Response Center&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://security.googleblog.com/2023/01/supporting-use-of-rust-in-chromium.html" rel="noopener noreferrer"&gt;[27] Google Online Security Blog: Supporting the Use of Rust in the Chromium Project&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>rust</category>
      <category>go</category>
      <category>c</category>
      <category>database</category>
    </item>
  </channel>
</rss>
