<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by RapidFork Technology on Medium]]></title>
        <description><![CDATA[Stories by RapidFork Technology on Medium]]></description>
        <link>https://medium.com/@rapidfork?source=rss-cadd4d707a59------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lwq9SmOCTjtY_0WiF6gV0w@2x.jpeg</url>
            <title>Stories by RapidFork Technology on Medium</title>
            <link>https://medium.com/@rapidfork?source=rss-cadd4d707a59------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 21:23:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rapidfork/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Merge Arrays or Arrays of Objects in JavaScript/TyepScript]]></title>
            <link>https://rapidfork.medium.com/merge-arrays-or-arrays-of-objects-in-javascript-tyepscript-1f7c4e83a94a?source=rss-cadd4d707a59------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f7c4e83a94a</guid>
            <dc:creator><![CDATA[RapidFork Technology]]></dc:creator>
            <pubDate>Sun, 19 May 2024 13:06:22 GMT</pubDate>
            <atom:updated>2024-05-19T13:06:22.415Z</atom:updated>
            <content:encoded><![CDATA[<p>To merge an array of objects in JavaScript, you can use various methods depending on your specific requirements. Here are some common approaches:</p><h3>1. Using Array.prototype.reduce</h3><p>This method is useful if you want to merge all objects into a single object.</p><pre>const arrayOfObjects = [<br>    { a: 1, b: 2 },<br>    { b: 3, c: 4 },<br>    { d: 5 }<br>];</pre><pre>const mergedObject = arrayOfObjects.reduce((acc, obj) =&gt; {<br>    return { ...acc, ...obj };<br>}, {});</pre><pre>console.log(mergedObject); // Output: { a: 1, b: 3, c: 4, d: 5 }</pre><h3>2. Using Object.assign</h3><p>This method is also useful for merging all objects into a single object.</p><pre>const arrayOfObjects = [<br>    { a: 1, b: 2 },<br>    { b: 3, c: 4 },<br>    { d: 5 }<br>];</pre><pre>const mergedObject = Object.assign({}, ...arrayOfObjects);</pre><pre>console.log(mergedObject); // Output: { a: 1, b: 3, c: 4, d: 5 }</pre><h3>3. Merging with Deep Copy (using Lodash)</h3><p>If you need a deep merge (for nested objects), you can use Lodash’s merge function.</p><p>First, install Lodash:</p><p>Then use it in your code:</p><pre>const _ = require(&#39;lodash&#39;);</pre><pre>const arrayOfObjects = [<br>    { a: 1, b: { x: 1, y: 2 } },<br>    { b: { y: 3, z: 4 }, c: 4 },<br>    { d: 5 }<br>];</pre><pre>const mergedObject = _.merge({}, ...arrayOfObjects);</pre><pre>console.log(mergedObject); // Output: { a: 1, b: { x: 1, y: 3, z: 4 }, c: 4, d: 5 }</pre><h3>4. Using ES6 Spread Operator</h3><p>For merging objects into a single object with simple key-value pairs.</p><pre>const arrayOfObjects = [<br>    { a: 1, b: 2 },<br>    { b: 3, c: 4 },<br>    { d: 5 }<br>];</pre><pre>const mergedObject = arrayOfObjects.reduce((acc, obj) =&gt; ({ ...acc, ...obj }), {});</pre><pre>console.log(mergedObject); // Output: { a: 1, b: 3, c: 4, d: 5 }</pre><h3>5. Merging Arrays of Objects by Combining Values</h3><p>If you need to combine values of objects based on a specific key:</p><pre>const arrayOfObjects = [<br>    { id: 1, value: 10 },<br>    { id: 2, value: 20 },<br>    { id: 1, value: 30 },<br>    { id: 2, value: 40 }<br>];</pre><pre>const mergedById = arrayOfObjects.reduce((acc, obj) =&gt; {<br>    const found = acc.find(item =&gt; item.id === obj.id);<br>    if (found) {<br>        found.value += obj.value;<br>    } else {<br>        acc.push({ ...obj });<br>    }<br>    return acc;<br>}, []);</pre><pre>console.log(mergedById); // Output: [ { id: 1, value: 40 }, { id: 2, value: 60 } ]</pre><p>Choose the method that best fits your needs based on the complexity of the objects you’re dealing with and whether you need a shallow or deep merge.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f7c4e83a94a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Various Similarity Metrics for Vector Data and Language Embeddings]]></title>
            <link>https://rapidfork.medium.com/various-similarity-metrics-for-vector-data-and-language-embeddings-23a745f7f5a7?source=rss-cadd4d707a59------2</link>
            <guid isPermaLink="false">https://medium.com/p/23a745f7f5a7</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[RapidFork Technology]]></dc:creator>
            <pubDate>Sat, 16 Mar 2024 17:57:41 GMT</pubDate>
            <atom:updated>2024-03-16T17:57:41.135Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HbDKQcwFMKHFnNNAMg24mg.jpeg" /></figure><p><strong>tldr; Please skip the first section</strong></p><h3>What’s a vector?</h3><p><a href="https://rapidfork.medium.com/vector-f10090c57c96">https://rapidfork.medium.com/vector-f10090c57c96</a></p><h3>What’s embedding?</h3><p><a href="https://rapidfork.medium.com/embedding-f311e619898d">https://rapidfork.medium.com/embedding-f311e619898d</a></p><h3><strong>Various Metrics</strong></h3><ul><li><strong>Cosine Similarity:</strong> This metric measures the cosine of the angle between two non-zero vectors of an inner product space, which is widely used in high-dimensional positive spaces such as text analysis. In language embeddings, cosine similarity helps in finding the closeness of two words or documents irrespective of their size.</li><li><strong>Euclidean Distance (L2 norm):</strong> This is the “ordinary” straight-line distance between two points in Euclidean space. In the context of vector data and language embeddings, it measures the actual distance between points (or vectors), often used in clustering algorithms like K-means.</li></ul><blockquote><strong>What’s a norm now?</strong></blockquote><blockquote>Imagine you and your friends are in different parts of a park and you’re all planning to meet up at the ice cream stand. The “norm” is like your own personal rule for how you decide the distance you need to walk. But instead of being a single rule, there are different kinds of “rules” you can choose from, depending on what’s important to you:</blockquote><blockquote><strong>L1 Norm (Manhattan or Taxicab Norm):</strong> This is like deciding to walk only along the paths in the park, turning left or right as needed, but not cutting across the grass. The distance you measure using this rule is like adding up the total number of steps you take along all the paths to get to the meeting point.</blockquote><blockquote><strong>L2 Norm (Euclidean Norm):</strong> This is like using a big ruler to stretch a straight line from where you are to the ice cream stand and walking directly in that straight line, even if it means cutting across the grass. The distance you measure here is the shortest possible one, like the straight line distance between you and the stand.</blockquote><blockquote><strong>L∞ Norm (Infinity or Maximum Norm):</strong> This is a bit different. Imagine you can only move horizontally or vertically, but you want to minimize the longer of the two distances. So, if you’re far to the east but only a little to the north of the stand, you focus on reducing that east-west distance as much as possible, even if it means not improving the north-south distance.</blockquote><ul><li><strong>Manhattan Distance (L1 norm)</strong>: Also known as “city block” distance, this metric measures the distance between two points in a grid-based on a strictly horizontal and/or vertical path, akin to the streets of Manhattan. It is useful when the effect of outliers needs to be diminished, and variances across dimensions are equal.</li><li><strong>Jaccard Similarity:</strong> This is used for comparing the similarity and diversity of sample sets. It measures how many attributes are shared between two documents as a proportion of the total number of attributes across them. It’s especially useful in cases where the data representation is binary (like set-based data or high-dimensional data).</li><li><strong>Hamming Distance:</strong> This measures the distance between two strings of equal length by counting the number of positions at which the corresponding symbols are different. It’s useful in scenarios where the similarity between two strings (binary strings, for example) needs to be assessed.</li><li><strong>Pearson Correlation:</strong> While not a distance metric in the strict sense, Pearson correlation measures the linear correlation between two variables. In the context of language embeddings and vector data, it can help understand the linear similarity between different documents or word vectors.</li><li><strong>Spearman’s Rank Correlation:</strong> Similar to Pearson, but it measures the monotonicity of the relationship between two variables rather than the linearity. This can be particularly useful for non-parametric data in language models.</li><li><strong>Levenshtein Distance:</strong> Although more commonly used in string manipulation, this metric measures the minimum number of single-character edits required to change one word into the other. It’s useful in text analysis for tasks like spelling correction or similarity checks.</li><li><strong>Angular Distance:</strong> This measures the angle between two vectors, which can be related to cosine similarity but provides an actual angular measure rather than the cosine of the angle.</li><li><strong>Mahalanobis Distance:</strong> This is a measure of the distance between a point and a distribution. In the context of vector data, it’s useful for identifying outliers or performing cluster analysis when the data has varying scales and the variables are correlated.</li><li><strong>Tanimoto Coefficient (Jaccard Coefficient for binary data):</strong> This is used to measure the similarity and diversity between two sets. It is similar to the Jaccard similarity but specifically adjusted for binary data vectors. This metric is widely used in cheminformatics to measure the similarity between chemical structures.</li><li><strong>Dice’s Coefficient:</strong> This is another similarity measure related to Jaccard’s Index, but it gives more weight to the intersection of the two sets. It is calculated as twice the intersection of the sets divided by the sum of their sizes. It’s often used in ecological and biological data analysis.</li><li><strong>Hellinger Distance:</strong> This is used in statistics to quantify the similarity between two probability distributions. It is related to the Bhattacharyya distance and is used in various applications, including text analysis and image processing.</li><li><strong>Bhattacharyya Distance:</strong> This measures the similarity of two discrete or continuous probability distributions; it is closely related to the Hellinger distance and is often used in classification problems.</li><li><strong>KL Divergence (Kullback-Leibler Divergence):</strong> This is a measure from information theory, representing the difference between two probability distributions over the same variable. It’s a non-symmetric measure and can be seen as the amount of information lost when one distribution approximates the other. This is especially useful in machine learning models and natural language processing for measuring how one language model diverges from another.</li><li><strong>Wasserstein Distance (Earth Mover’s Distance):</strong> This metric is a measure of the distance between two probability distributions, which is interpreted as the minimum amount of work needed to transform one distribution into the other. It’s widely used in optimal transport problems, image recognition, and deep learning.</li><li><strong>Canberra Distance:</strong> This is a numerical measure of the distance between pairs of points in a vector space, particularly used when the data contains zeros, as it gives more weight to these discrepancies. It’s useful for high-dimensional data analysis and genetic data.</li><li><strong>Chebyshev Distance:</strong> This is a distance measure defined as the greatest of difference between any coordinate of two vectors in a vector space. It’s also known as maximum value distance and is particularly useful in infinity norm problems, grid-based pathfinding, and when considering the worst-case scenario between different dimensions.</li><li><strong>Minkowski Distance:</strong> A generalization of both the Euclidean distance and the Manhattan distance. It’s a parameterized metric that can be adjusted according to the problem requirements. When the parameter is set to 1, it becomes the Manhattan distance, and when it’s set to 2, it becomes the Euclidean distance.</li><li><strong>Normalized Google Distance:</strong> Based on information content from search engine results, it measures the semantic similarity between words or phrases by utilizing the number of hits returned by a search engine for various queries.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23a745f7f5a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vector]]></title>
            <link>https://rapidfork.medium.com/vector-f10090c57c96?source=rss-cadd4d707a59------2</link>
            <guid isPermaLink="false">https://medium.com/p/f10090c57c96</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[physics]]></category>
            <dc:creator><![CDATA[RapidFork Technology]]></dc:creator>
            <pubDate>Sat, 16 Mar 2024 17:56:53 GMT</pubDate>
            <atom:updated>2024-03-16T17:56:53.670Z</atom:updated>
            <content:encoded><![CDATA[<p>A vector is a mathematical object that has magnitude (size or length) and direction. Vectors are used to represent quantities that have both of these characteristics. In many contexts, a vector is represented as an array of numbers called its components, which denote its direction and magnitude within a certain frame of reference.</p><p>For example, in a two-dimensional space, a vector can be represented as [<em>x</em>,<em>y</em>], where <em>x</em> and <em>y</em> are the distances the vector moves along the X and Y axes, respectively. In three-dimensional space, a vector would have three components, represented as [<em>x</em>,<em>y</em>,<em>z</em>].</p><p>Vectors are fundamental in physics, engineering, and computer science, particularly in areas such as mechanics, electromagnetism, and graphics. In data science and machine learning, vectors are often used to represent data points in high-dimensional spaces.</p><blockquote>Imagine you’re in a park, and you want to go to the ice cream stand. The direction you need to walk and the distance to the stand together form what we call a “vector” in everyday language.</blockquote><blockquote>In this scenario:</blockquote><blockquote>Direction: The specific path or direction you need to take to get to the ice cream stand, like “straight towards the big oak tree” or “towards the lake.”</blockquote><blockquote>Distance (or Magnitude): How far you need to walk, like “100 steps” or “across two soccer fields.”</blockquote><blockquote>So, if I were to tell you, “Walk 100 steps towards the lake,” I’ve given you a “vector” in everyday terms. This vector helps you know exactly where to go and how far. In math and science, we use numbers and angles to describe this same idea, but it all boils down to the concept of having both a direction and a magnitude.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f10090c57c96" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedding]]></title>
            <link>https://rapidfork.medium.com/embedding-f311e619898d?source=rss-cadd4d707a59------2</link>
            <guid isPermaLink="false">https://medium.com/p/f311e619898d</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[RapidFork Technology]]></dc:creator>
            <pubDate>Sat, 16 Mar 2024 17:55:37 GMT</pubDate>
            <atom:updated>2024-03-16T17:55:37.623Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GMhjhmJewCn384wI1kD4tw.jpeg" /></figure><p>An “embedding” in the context of machine learning and data science refers to a way of converting categorical data, like words or items, into vectors of real numbers. This transformation allows complex, high-dimensional data to be used in mathematical models, typically for tasks in natural language processing (NLP), recommendation systems, and more.</p><h3>In Language (Word Embeddings):</h3><p>When we talk about embeddings in language, we mean word embeddings. These are representations where each word in a vocabulary is mapped to a vector in a continuous vector space. The idea is that words with similar meanings will be closer to each other in this space than words with different meanings. This is achieved by analyzing the words’ contexts — how they’re used in sentences. Common models for creating word embeddings include Word2Vec, GloVe, and FastText.</p><p>For example, in a word embedding space, words like “king” and “queen” might be closer together than “king” and “apple,” reflecting their semantic similarity.</p><h3>In Other Domains:</h3><p>While word embeddings are common, the concept applies beyond language. For example:</p><ul><li><strong>Item Embeddings: </strong>In recommendation systems, items like movies or products can be embedded into a vector space. Similar items will be closer together, which helps in making recommendations that are “similar” to a user’s past preferences.</li><li><strong>Graph Embeddings:</strong> Nodes in a network (like users in a social network) can be embedded such that the geometric relationships between points (vectors) reflect the structure of the network, like which users are more connected.</li></ul><h3>Why Use Embeddings at all?</h3><ul><li><strong>Dimensionality Reduction:</strong> Embeddings help reduce the dimensionality of categorical variables, making them more manageable for algorithms to process.</li><li><strong>Semantic Meaning:</strong> In text, embeddings capture deeper semantic meaning that isn’t possible with simpler representations like one-hot encoding.</li><li><strong>Generalization:</strong> By representing items as points in a continuous space, models can better generalize from seen to unseen data, as they can infer properties from the position in the vector space.</li></ul><h3>What’s dimensionality?</h3><p><a href="https://rapidfork.medium.com/dimensionality-0a4a8e64a0e6">https://rapidfork.medium.com/dimensionality-0a4a8e64a0e6</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f311e619898d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dimensionality]]></title>
            <link>https://rapidfork.medium.com/dimensionality-0a4a8e64a0e6?source=rss-cadd4d707a59------2</link>
            <guid isPermaLink="false">https://medium.com/p/0a4a8e64a0e6</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[RapidFork Technology]]></dc:creator>
            <pubDate>Sat, 16 Mar 2024 17:54:50 GMT</pubDate>
            <atom:updated>2024-03-16T17:54:50.502Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GMhjhmJewCn384wI1kD4tw.jpeg" /></figure><p>“Dimensionality” refers to the number of attributes or features that represent a data point in a dataset. In a simple sense, it’s like the number of different characteristics or dimensions we have information on. For example, if you are collecting data on houses, the dimensions might include the number of bedrooms, square footage, price, etc. Each of these is a dimension of your data.</p><p>In high-dimensional spaces, such as those often found in machine learning, each data point can have hundreds, thousands, or even millions of dimensions. High dimensionality can make data analysis more challenging, a phenomenon known as the “curse of dimensionality,” which can lead to issues like overfitting and increased computational complexity. Reducing dimensionality through techniques like principal component analysis (PCA) or embeddings can help alleviate these problems by distilling the most informative features into a lower-dimensional space.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0a4a8e64a0e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter’s UI Framework: Deep Dive Into Its Internals]]></title>
            <link>https://rapidfork.medium.com/flutters-ui-framework-deep-dive-into-its-internals-07dbcd96f0a6?source=rss-cadd4d707a59------2</link>
            <guid isPermaLink="false">https://medium.com/p/07dbcd96f0a6</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[user-interface]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[RapidFork Technology]]></dc:creator>
            <pubDate>Thu, 02 Nov 2023 21:27:11 GMT</pubDate>
            <atom:updated>2023-11-02T21:27:11.469Z</atom:updated>
            <content:encoded><![CDATA[<p>Flutter, Google’s UI toolkit, has rapidly gained popularity for its ability to build natively compiled applications for mobile, web, and desktop from a single codebase. At the heart of Flutter is its rich UI framework, allowing developers to create visually stunning applications. But how does it all work under the hood? Let’s embark on a journey to unravel the depths of Flutter’s UI framework, enabling you to harness its full potential.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wOjRSye2HsBPdgYY4rBxxw.png" /></figure><h3>The Layered Architecture</h3><p>Flutter’s architecture is modular and layered, offering a hierarchy of libraries:</p><ol><li>Framework: The Dart-based, high-level set of libraries that most developers interact with directly.</li><li>Engine: Written primarily in C++, this bridges the gap between the framework and Skia.</li><li>Embedder: This platform-specific code embeds the Flutter app into its respective environment (iOS, Android, web).</li></ol><p>Understanding this layered approach is pivotal for optimizing performance and ensuring smooth user experiences.</p><h3>Widgets: The Building Blocks</h3><p>Everything in Flutter starts and ends with widgets. They’re the fundamental building blocks of your application’s UI.</p><h3>Element &amp; Render Trees</h3><p>Widgets describe how the UI should look, but they’re ephemeral. Flutter uses widgets to produce and update the Element Tree and the Render Tree:</p><ul><li>Element Tree: Represents a runtime instance of a widget. It’s what you’d get if you walked through the widget tree and instantiated each widget.</li><li>Render Tree: Contains the visual aspects of widgets. Each RenderObject knows how to paint itself and lay out its children.</li></ul><h3>The Lifecycle of a Widget</h3><p>Widgets have a short-lived lifecycle. When the state or data changes, instead of updating the existing widget, Flutter creates a new widget. This immutability ensures consistency and simplicity in the UI description but raises the question: “Isn’t that inefficient?” The magic answer lies in Flutter’s diffing algorithm, which efficiently compares the old and new widget trees and updates only the differences.</p><h3>Painting: The Skia Connection</h3><p>Flutter’s engine contains the Skia graphics library, a high-performance, open-source 2D graphics library. Every visual element you see in a Flutter app is a series of Skia commands.</p><h3>Custom Painting</h3><p>For custom graphics, developers often use the CustomPainter class. Every draw method on its Canvas (e.g., drawCircle, drawPath) translates to Skia commands. This direct connection with Skia ensures that Flutter&#39;s painting operations are fast and efficient.</p><h3>Layout &amp; Constraints</h3><p>In Flutter, layout is a two-pass system:</p><ol><li>Parent to Child: Parents set constraints (minimum and maximum width and height) for their children.</li><li>Child to Parent: Children, after laying out, inform their parents of their size.</li></ol><p>This system ensures that, even with complex layouts, Flutter can quickly determine the size and position of each widget on the screen.</p><h3>Gestures &amp; Interactivity</h3><p>Flutter’s gesture system is a crucial aspect of its interactive prowess. Raw pointer events are captured and passed through a series of Gesture Recognizers. These recognizers determine specific gestures (tap, double-tap, swipe). An arena system ensures that, in case of conflicting gestures, only one recognizer wins.</p><h3>Deep Insights: Performance &amp; Customization</h3><ul><li>Repaint Boundaries: Not all widgets need to be redrawn all the time. Repaint boundaries isolate sections of the widget tree, ensuring that changes in one section don’t unnecessarily repaint other sections.</li><li>Custom Widgets: Understanding the basics of the RenderObject system can empower you to create custom widgets from scratch. For instance, if you&#39;re building a unique shape or a complex visual element, diving deep into the rendering layer can be beneficial.</li><li>Platform Channels: For platform-specific code, Flutter offers platform channels. While not strictly UI-related, they’re crucial for apps that need deeper integration with OS-specific features.</li></ul><h3>Diffing algorithms</h3><p>Flutter’s diffing algorithm is a fundamental part of its performance optimizations, especially when updating the UI. Unlike some other frameworks that use a virtual DOM and compare differences there, Flutter operates directly on the widget tree. The process is quite different and interesting. Let’s dive into it:</p><h3>Widget Reconstruction</h3><p>In Flutter, widgets are lightweight and immutable. When the state of an application changes, Flutter doesn’t modify existing widgets. Instead, it rebuilds the widget tree. This might seem inefficient at first, but due to the lightweight nature of widgets and Flutter’s efficient diffing algorithm, this process is highly optimized.</p><h3>Element Tree: The Stable Backbone</h3><p>While widgets are ephemeral, the element tree remains stable. Each widget can create an Element object that remains in memory over time. The Element acts as a persistent handle to a location in the widget tree.</p><p>When Flutter rebuilds the widget tree, it tries to match the newly built widgets with the existing elements. This process is where the diffing comes into play.</p><h3>Diffing Process</h3><ol><li>Keyed Matching: Widgets can have an optional Key property. If a widget has a key, Flutter can quickly and accurately match the widget to its corresponding element, even if the widget&#39;s position in the tree has changed. This is especially useful for lists where items might be added, removed, or reordered.</li><li>Type Matching: If no key is provided, Flutter tries to match widgets and elements based on their runtime type. If a widget of the same type is found in the same location as before, Flutter will reuse the element.</li><li>Reconciliation: After matching, any unmatched elements are unmounted (i.e., removed from the tree). New widgets that don’t match any existing element result in the creation of new elements.</li><li>Component Update: For matched elements, Flutter calls the update method, passing in the new widget. This step is where properties might be updated, and the underlying render tree might be marked as &quot;dirty&quot; to schedule a repaint.</li><li>Render Tree Update: Changes in the widget or element tree may lead to updates in the render tree. The render tree, being more heavyweight, is updated selectively. Only “dirty” nodes (those that need layout or painting updates) are reprocessed. This ensures that only necessary graphics operations are sent to the GPU.</li></ol><h3>Benefits</h3><ul><li>Performance: By reusing elements and render objects, Flutter avoids unnecessary object creation and garbage collection. This leads to smoother animations and interactions.</li><li>State Preservation: Stateful widgets hold state that might not change even if the widget rebuilds. By reusing elements and associated stateful widgets, Flutter ensures that state is preserved across rebuilds.</li><li>Explicit Control: Developers have fine-grained control over the diffing process using keys. This ensures that even in complex scenarios, like list animations, the UI updates as intended.</li></ul><p>Flutter’s diffing algorithm is a core part of its reactive UI paradigm. By efficiently matching new widgets with existing elements and selectively updating the render tree, Flutter achieves high performance while providing developers with a simple and intuitive UI description mechanism. This approach contrasts with the virtual DOM diffing used in some web frameworks but is well-suited for the specific challenges and opportunities of mobile app development.</p><h3>So</h3><p>Flutter’s UI framework is a testament to its power and flexibility. By understanding its internals, from the widget lifecycle to the Skia rendering engine, developers can make informed decisions, optimize performance, and truly harness the potential of this remarkable framework.</p><p>Empower yourself with this knowledge, and you’ll not only build beautiful Flutter apps but also efficient and high-performance ones. Whether you’re selecting components, structuring your application, or designing widgets from scratch, a deep understanding of Flutter’s internals will always guide you to the best solutions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=07dbcd96f0a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Infinite Memory and Python Wizards: The True Magic of Garbage Collection]]></title>
            <link>https://rapidfork.medium.com/infinite-memory-and-python-wizards-the-true-magic-of-garbage-collection-665ba172fc67?source=rss-cadd4d707a59------2</link>
            <guid isPermaLink="false">https://medium.com/p/665ba172fc67</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[RapidFork Technology]]></dc:creator>
            <pubDate>Sun, 25 Jun 2023 04:24:56 GMT</pubDate>
            <atom:updated>2023-06-25T04:24:56.755Z</atom:updated>
            <content:encoded><![CDATA[<p>Infinite Memory and Python Wizards: The True Magic of Garbage Collection</p><p>Imagine you’re a Python wizard, and your wand has the power to conjure infinite memory. Your spells are so powerful that you never have to worry about running out of memory. This, my fellow Pythonistas, is the enchanting world that garbage collection tries to create. But wait, let’s not get ahead of ourselves. Let’s take a magical journey through the realms of Python’s garbage collection.</p><p>Most muggles, when asked about garbage collection, would mumble something about it being Python’s way of automatically cleaning up memory that’s no longer needed. But that’s like saying a wizard’s job is to wave a wand and mutter incantations. True, but oh-so-ordinary and missing the magic!</p><p>Garbage collection is not just a janitor; it’s an illusionist! It’s the grand sorcerer that conjures a spell to make Python believe it has an infinite cauldron of memory. The actual cleaning up of memory is just the sleight of hand, the trick behind the grand illusion.</p><p>Now, let’s brew a potion of understanding. Imagine a cauldron that never empties. You could keep adding ingredients forever. In a computer with infinite memory, Python could keep using memory without a second thought. But alas, in the real world, memory is like a rare magical ingredient. That’s where our hero, the Garbage Collector, steps in, waving its wand to efficiently manage memory, giving Python the illusion of a bottomless cauldron.</p><p>But beware, young wizards! With great power comes great responsibility. Garbage collection might be a master of memory illusions, but it’s not an all-seeing oracle. It doesn’t know how to properly handle other magical artifacts like file scrolls or network crystal balls.</p><p>Relying on garbage collection to manage these resources is like expecting a spell to clean up your wizard’s tower. You must take matters into your own hands. When you’re done reading a file scroll, seal it with the with spell. When you’re finished scrying with your network crystal ball, close the connection with an incantation.</p><p>And a word of caution: don’t rely on the mystical destructors (__del__ methods) to always clean up after your spells. They are like mischievous house-elves, sometimes not doing what you expect.</p><p>In the spellbook of Python, garbage collection is one of the most powerful enchantments. But remember, it’s not just about cleaning up; it’s about creating a world of infinite possibilities with memory. As Python wizards, we must wield our wands wisely, conjuring not just efficiently, but also responsible spells in our magical realm of coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=665ba172fc67" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ensuring Data Consistency Across Distributed Systems: Strategies for Modern Applications]]></title>
            <link>https://rapidfork.medium.com/ensuring-data-consistency-across-distributed-systems-strategies-for-modern-applications-249e3742702e?source=rss-cadd4d707a59------2</link>
            <guid isPermaLink="false">https://medium.com/p/249e3742702e</guid>
            <category><![CDATA[fintech]]></category>
            <category><![CDATA[banking]]></category>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[RapidFork Technology]]></dc:creator>
            <pubDate>Tue, 11 Apr 2023 12:14:13 GMT</pubDate>
            <atom:updated>2023-04-11T12:14:13.345Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In today’s fast-paced and ever-evolving technology landscape, businesses demand highly scalable and resilient applications. As applications grow more complex, maintaining data consistency across distributed systems becomes increasingly challenging. In this article, we will explore different strategies to ensure data consistency across multiple databases or resources, including Two-Phase Commit (2PC), Optimistic Concurrency Control (OCC), and more. We will also discuss some considerations for containerized environments like Kubernetes.</p><p>Two-Phase Commit (2PC) and Optimistic Concurrency Control (OCC)</p><p><strong>Two-Phase Commit (2PC) </strong>is a protocol that ensures distributed transactions are atomic and consistent across multiple databases or resources. It consists of two main phases: the prepare phase and the commit phase. During the prepare phase, participating resources lock necessary resources and write updates to a log. If all resources are prepared to commit, the commit phase proceeds, and each resource makes the changes permanent and releases the locks.</p><p><strong>Optimistic Concurrency Control (OCC),</strong> on the other hand, allows transactions to proceed without locking resources, detecting conflicts when the transaction attempts to commit. If a conflict is detected, the transaction is aborted, and a retry mechanism is initiated. OCC can be an attractive alternative to 2PC when contention is low, as it avoids the overhead of locking resources.</p><h3>Handling Failures and Recovery in 2PC</h3><p>One of the challenges with 2PC is handling failures, such as host machine crashes or pod failures in containerized environments like Kubernetes. A coordinator log can be used to record the transaction progress during the 2PC protocol, enabling the recovery of the transaction state and resumption of the protocol from the point of failure. However, storing the coordinator log on the local machine is not suitable for containerized environments, where pods can be stateless and ephemeral.</p><h3>Strategies for 2PC in Containerized Environments</h3><p>To address the challenges of <strong>2PC</strong> in containerized environments, you can employ the following strategies:</p><ol><li><strong>External durable storage:</strong> Store the coordinator log on a durable and highly available external storage system, such as a distributed file system (e.g., <strong>Hadoop HDFS</strong>), a cloud-based storage service (e.g., <strong>Amazon S3</strong>), or a distributed database (e.g., <strong>Apache Cassandra</strong>).</li><li><strong>Distributed transaction coordinator:</strong> Use a distributed transaction coordinator that can tolerate node failures, utilizing consensus algorithms like <strong>Paxos</strong> or <strong>Raft</strong> to ensure that a majority of nodes agree on the transaction state. Distributed transaction coordinators can be found in systems like <strong>ZooKeeper</strong>, <strong>etcd</strong>, or <strong>Apache Kafka</strong>.</li><li><strong>Stateless transaction manager</strong>: In a Kubernetes environment, use stateless transaction managers that rely on external storage for maintaining transaction states. This approach allows the transaction manager to recover the transaction state from external storage if a pod fails or is rescheduled.</li></ol><h3>Modern Industrial Practices</h3><p>In modern industry practice, the choice of solution largely depends on the specific requirements of the project and the priorities of the organization. Some common patterns and technologies that have gained popularity in recent years include microservices architecture, event-driven architecture, distributed databases, hybrid transactional/analytical processing (HTAP) systems, and cloud-native solutions. Each approach comes with its trade-offs in terms of complexity, performance, and fault tolerance, so it’s essential to carefully evaluate your application’s requirements and choose the most suitable strategy accordingly.</p><h3>Conclusion</h3><p>Ensuring data consistency across distributed systems is a critical requirement for many modern applications. The strategies discussed in this article, including 2PC, OCC, and various approaches for handling failures and recovery, can help you achieve data consistency while considering the specific needs and constraints of your application. By understanding the trade-offs and selecting the appropriate strategy, you can build highly scalable, resilient, and consistent applications that meet the demands of today’s businesses.</p><p>Whether you are dealing with a legacy system that requires modifications to accommodate new requirements or building a new application from scratch, it’s crucial to weigh the benefits and drawbacks of each strategy in the context of your specific use case. By carefully planning and selecting the right approach for your distributed system, you can ensure that your application remains robust, scalable, and fault-tolerant, even as it evolves over time.</p><p>As the technology landscape continues to change rapidly, it’s essential to stay informed about the latest trends and best practices for distributed systems. By learning from the experiences of others and adapting your strategies as needed, you can continue to build and maintain high-quality applications that deliver value to your users and your organization.</p><p>In conclusion, the challenges of maintaining data consistency across distributed systems are complex, but by using a combination of strategies and technologies, you can successfully navigate these challenges and build enterprise-grade applications. The key is to understand the trade-offs and choose the most suitable strategy for your specific requirements, ensuring that your application remains scalable, resilient, and consistent throughout its lifecycle.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=249e3742702e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Preserving State with Keys in Flutter]]></title>
            <link>https://rapidfork.medium.com/preserving-state-with-keys-in-flutter-b83a7bff6581?source=rss-cadd4d707a59------2</link>
            <guid isPermaLink="false">https://medium.com/p/b83a7bff6581</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[ui]]></category>
            <dc:creator><![CDATA[RapidFork Technology]]></dc:creator>
            <pubDate>Fri, 10 Mar 2023 22:06:28 GMT</pubDate>
            <atom:updated>2023-03-10T22:06:28.289Z</atom:updated>
            <content:encoded><![CDATA[<p>When building a Flutter app, developers often need to preserve the state of certain widgets when modifying a collection. This is where keys come in handy! By adding keys to the top of a widget tree, developers can ensure that their apps maintain the same state even when widgets are moved around. In this article, we’ll explore when to use keys, where to put them, and which key is right for you.</p><p>Let’s start by taking a look at when you need to use keys. Generally speaking, if you’re adding, removing or reordering a collection of widgets of the same type that hold some state, you should use keys. A great example of this is a to-do list app. When using the app, users should be able to reorder items based on priority and remove them when they’re done. Another example is an app like Hacker News which requires keys to prevent story widgets from incorrectly picking up old state when the list view is rebuilt.</p><p>Now that we know when we need keys, let’s discuss where to put them in your widget tree. The answer: specify a key at the top of the widget subtree that you need to preserve. It’s important not to place keys on the first stateful widget as doing so will result in unexpected behavior. To demonstrate this, imagine we wrap our colorful tile widgets with padding widgets but leave the keys on the tiles themselves. When we click the button, the tiles change to completely different random colors! To avoid this issue, it’s important to add keys at the level of padding widgets.</p><p>Finally, let’s talk about which key is right for you. If you’re storing text as part of your data set (like in a to-do list app), it’s probably best to use a value key where the text itself is the value. If you’re storing more complex data (like in an address book app), an object key might be most appropriate. Lastly, if there are multiple widgets in your collection with the same value or if you want to ensure each widget is distinct from all others, then you can use UniqueKey.</p><p>In summary, by understanding when and where to use keys and which key type is right for your project, developers can ensure their apps maintain their state even when modifying collections of widgets. So go forth and create amazing apps with confidence!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b83a7bff6581" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Breaking Down Python Concurrency: The Global Interpreter Lock(GIL) and Its Effect on…]]></title>
            <link>https://medium.com/swlh/breaking-down-python-concurrency-the-gil-and-its-effect-on-multi-threading-b5ab99083cb2?source=rss-cadd4d707a59------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5ab99083cb2</guid>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[RapidFork Technology]]></dc:creator>
            <pubDate>Sun, 19 Feb 2023 12:19:11 GMT</pubDate>
            <atom:updated>2023-02-20T04:27:37.585Z</atom:updated>
            <content:encoded><![CDATA[<h3>Breaking Down Python Concurrency: The Global Interpreter Lock(GIL) and Its Effect on Multi-threading</h3><h3>Introduction</h3><p>Python is a popular high-level programming language that is known for its simplicity, ease of use, and quick development. However, Python’s garbage collection mechanism relies on the Global Interpreter Lock (GIL) which can cause some limitations. This paper will explore the aspects of pointers in Python, particularly focusing on the impact of GIL on memory management, multi-threading, and CPU utilization. Additionally, specific examples will be provided to illustrate the limitations and workarounds.</p><h3>Memory Management and the Global Interpreter Lock (GIL)</h3><p>Python uses a garbage collector to automatically manage memory. The garbage collector frees memory by detecting and removing objects that are no longer being used by the program. However, the garbage collector relies on the Global Interpreter Lock (GIL) to function correctly. The GIL is a mechanism that prevents multiple threads from executing Python bytecodes at once. The GIL is necessary because Python’s memory management is not thread-safe, meaning that two threads cannot access the same memory location at the same time without the risk of corrupting data.</p><p>The GIL has some implications for memory management. For instance, it can prevent the garbage collector from running simultaneously in multiple threads. As a result, the memory occupied by the objects that are no longer being used will not be cleared until the garbage collector runs. This can lead to memory leaks and degrade performance.</p><p>Here’s an example that illustrates this limitation:</p><pre>import threading<br><br>class MyClass:<br>    def __init__(self):<br>        self.my_list = []<br><br>    def add_value(self, value):<br>        self.my_list.append(value)<br><br>my_object = MyClass()<br><br>def add_values():<br>    for i in range(1000000):<br>        my_object.add_value(i)<br><br>thread_1 = threading.Thread(target=add_values)<br>thread_2 = threading.Thread(target=add_values)<br><br>thread_1.start()<br>thread_2.start()<br><br>thread_1.join()<br>thread_2.join()<br><br>print(len(my_object.my_list))</pre><p>In this example, we define a class MyClass that has a list my_list. The add_value method adds a value to the list. We create an instance of the class my_object and then create two threads that call the add_values function. This function adds one million values to my_object.my_list. Finally, we print the length of my_object.my_list.</p><p>However, due to the GIL, the two threads cannot run in parallel, and the program takes longer to execute. Additionally, the garbage collector may not run during the execution of the threads, which means that the memory used by the values added to my_object.my_list may not be cleared. This can cause a memory leak and degrade performance.</p><h3>Multi-Threading and the Global Interpreter Lock (GIL)</h3><p>The Global Interpreter Lock (GIL) also affects multi-threading in Python. The GIL works by putting a lock on each variable and maintaining a usage counter. If a thread wants to access a variable that is already being used by another thread, it must wait until the first thread has released the variable. As a result, only one thread can execute Python bytecodes at once.</p><p>This limitation can have implications for multi-threaded programs that rely heavily on CPU-bound operations. For example, if a program has two threads that perform complex calculations, the GIL will prevent them from running in parallel, and the program will not benefit from the use of multiple CPU cores.</p><p>Here’s an example that illustrates this limitation:</p><pre>import threading<br><br>def fib(n):<br>    if n &lt;= 1:<br>        return n<br>    else:<br>        return fib(n-1) + fib(n-2)<br><br>def compute_fib():<br>    for i in range(30):<br>        print(fib(i))<br><br>thread_1 = threading.Thread(target=compute_fib)<br>thread_2 = threading.Thread(target=compute_fib)<br><br>thread_1.start()<br>thread_2.start()<br><br>thread_1.join()<br>thread_2.join()</pre><p>In this example, we define a `fib` function that computes the nth Fibonacci number. We also define a `compute_fib` function that computes the first 30 Fibonacci numbers by calling the `fib` function. We create two threads that call the `compute_fib` function and then start them. Finally, we wait for the threads to finish using the `join` method. However, due to the GIL, the two threads cannot execute Python bytecodes in parallel. As a result, the program does not benefit from the use of multiple CPU cores, and the execution time is the same as if we had used a single thread. CPU Utilization and Multi-Processing To utilize multiple CPU cores in Python, we can use the multiprocessing module. The multiprocessing module allows us to create multiple processes that run in parallel, each with its own interpreter and memory space. This means that each process can use its own CPU core to execute Python bytecodes without being affected by the GIL.</p><p>Here’s an example that illustrates how we can use the multiprocessing module to compute the Fibonacci sequence:</p><pre>import multiprocessing<br><br>def fib(n):<br>if n &lt;= 1:<br>return n<br>else:<br>return fib(n-1) + fib(n-2)<br><br>def compute_fib(start, end):<br>for i in range(start, end):<br>print(fib(i))<br><br>if name == &#39;main&#39;:<br>with multiprocessing.Pool(processes=2) as pool:<br>pool.starmap(compute_fib, [(0, 15), (15, 30)])</pre><p>In this example, we define a `fib` function that computes the nth Fibonacci number. We also define a `compute_fib` function that computes the Fibonacci sequence for a range of numbers by calling the `fib` function. We create a pool of two processes using the `multiprocessing.Pool` method and then use the `starmap` method to execute the `compute_fib` function for two ranges of numbers (0 to 15 and 15 to 30). The `starmap` method distributes the ranges of numbers across the two processes, and each process computes the Fibonacci sequence for its assigned range. Finally, the results are printed.</p><p>By using the multiprocessing module, we can utilize multiple CPU cores to execute Python bytecodes in parallel without being affected by the GIL. This can significantly improve the performance of CPU-bound operations.</p><h3>Conclusion</h3><p>In conclusion, pointers in Python can be affected by the Global Interpreter Lock (GIL) when it comes to memory management, multi-threading, and CPU utilization. The GIL is necessary to prevent multiple threads from accessing the same memory location at the same time, but it can limit the performance of multi-threaded and CPU-bound programs. To work around the GIL, we can use the multiprocessing module to utilize multiple CPU cores and execute Python bytecodes in parallel, each with its own interpreter and memory space. By doing so, we can improve the performance of CPU-bound operations and overcome the limitations of the GIL.</p><h3>Bonus: Performance Comparison — Multiprocessing vs Multi-threading(minus GIL constraint)</h3><p>In a truly multi-threaded environment where the GIL is not a constraint, we can achieve better performance by using multi-threading instead of multiprocessing. This is because multi-threading has less overhead than multiprocessing as it does not require the creation of new processes and does not need to serialize/deserialize data between processes.</p><p>Here’s an example that illustrates how we can use multi-threading to compute the Fibonacci sequence in a truly multi-threaded environment:</p><pre>import threading<br><br>def fib(n):<br>    if n &lt;= 1:<br>        return n<br>    else:<br>        return fib(n-1) + fib(n-2)<br><br>def compute_fib(start, end):<br>    for i in range(start, end):<br>        print(fib(i))<br><br>if __name__ == &#39;__main__&#39;:<br>    thread_1 = threading.Thread(target=compute_fib, args=(0, 15))<br>    thread_2 = threading.Thread(target=compute_fib, args=(15, 30))<br><br>    thread_1.start()<br>    thread_2.start()<br><br>    thread_1.join()<br>    thread_2.join()</pre><p>In this example, we define a fib function that computes the nth Fibonacci number. We also define a compute_fib function that computes the Fibonacci sequence for a range of numbers by calling the fib function. We create two threads that call the compute_fib function and then start them. Finally, we wait for the threads to finish using the join method.</p><p>In a truly multi-threaded environment, this approach can achieve better performance than the multiprocessing approach. However, in a GIL-constrained environment like Python, this approach does not perform as well because the GIL limits the execution of Python bytecodes in parallel across threads.</p><p>To conclude, when the GIL is not a constraint, we can achieve better performance by using multi-threading instead of multiprocessing. However, in a GIL-constrained environment like Python, multi-threading does not perform as well as multiprocessing. In such cases, we can use multiprocessing to utilize multiple CPU cores and execute Python bytecodes in parallel without being affected by the GIL.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5ab99083cb2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/breaking-down-python-concurrency-the-gil-and-its-effect-on-multi-threading-b5ab99083cb2">Breaking Down Python Concurrency: The Global Interpreter Lock(GIL) and Its Effect on…</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>