<?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 Yasir Naeem on Medium]]></title>
        <description><![CDATA[Stories by Yasir Naeem on Medium]]></description>
        <link>https://medium.com/@yasir.naeem?source=rss-b463fd93ac3b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KURkQAtLtNYmvwqkt7E9Iw.jpeg</url>
            <title>Stories by Yasir Naeem on Medium</title>
            <link>https://medium.com/@yasir.naeem?source=rss-b463fd93ac3b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 17:00:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yasir.naeem/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[Fastest ways to update multiple values and fields in Laravel]]></title>
            <link>https://medium.com/@yasir.naeem/fastest-ways-to-update-multiple-values-and-fields-in-laravel-9cbebe93e66b?source=rss-b463fd93ac3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cbebe93e66b</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Yasir Naeem]]></dc:creator>
            <pubDate>Mon, 17 Apr 2023 01:06:37 GMT</pubDate>
            <atom:updated>2023-04-17T01:06:37.365Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9vvAW7XmIAJ0uC83" /><figcaption>Photo by <a href="https://unsplash.com/@lalonchera?utm_source=medium&amp;utm_medium=referral">lalo Hernandez</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>One of the fastest ways to update multiple values and fields with different ids in Laravel’s Eloquent is by using the update() method with whereIn().</p><p>Here’s an example of how to use whereIn() to update multiple rows in Laravel&#39;s Eloquent with dynamic values:</p><pre>$ids = [1, 2, 3, 4];<br>$values = [<br>    [&#39;name&#39; =&gt; &#39;John&#39;, &#39;age&#39; =&gt; 25],<br>    [&#39;name&#39; =&gt; &#39;Mary&#39;, &#39;age&#39; =&gt; 30],<br>    [&#39;name&#39; =&gt; &#39;Bob&#39;, &#39;age&#39; =&gt; 35],<br>    [&#39;name&#39; =&gt; &#39;Alice&#39;, &#39;age&#39; =&gt; 40]<br>];<br><br>$caseClauses = &#39;&#39;;<br>$bindings = [];<br><br>foreach ($values as $index =&gt; $value) {<br>    $id = $ids[$index];<br>    $caseClauses .= &quot;WHEN id = ? THEN ? ELSE name END as name_$id, &quot; .<br>                    &quot;WHEN id = ? THEN ? ELSE age END as age_$id, &quot;;<br>    $bindings[] = $id;<br>    $bindings[] = $value[&#39;name&#39;];<br>    $bindings[] = $id;<br>    $bindings[] = $value[&#39;age&#39;];<br>}<br><br>$updateData = rtrim($caseClauses, &#39;, &#39;);<br><br>DB::table(&#39;users&#39;)<br>    -&gt;whereIn(&#39;id&#39;, $ids)<br>    -&gt;update(DB::raw(&quot;CASE $updateData&quot;), $bindings);</pre><p>In the example above, we are updating the name and age fields of the users table for the ids specified in the $ids array. The values to update are specified in the $values array.</p><p>We use whereIn() to find the rows that match the ids in the $ids array. Then we use the update() method to update the name and age fields using the CASE statement in DB::raw(). This allows us to update the fields with dynamic values based on the specified ids.</p><p>The time complexity of this method is O(n), where n is the number of rows to update. This is because we are only updating a fixed number of rows and fields, so the time complexity does not depend on the size of the table.</p><p>Other methods, such as using a loop to update each row individually or using a subquery to update the rows, can have a time complexity of O(n²) or worse, depending on the size of the table. Therefore, using whereIn() with update() is generally faster and more efficient.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cbebe93e66b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native’s New Architecture]]></title>
            <link>https://medium.com/@yasir.naeem/react-natives-new-architecture-bd4d212abb27?source=rss-b463fd93ac3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd4d212abb27</guid>
            <category><![CDATA[jsi]]></category>
            <category><![CDATA[new-architecture]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[hermes]]></category>
            <category><![CDATA[turbo-module]]></category>
            <dc:creator><![CDATA[Yasir Naeem]]></dc:creator>
            <pubDate>Fri, 24 Mar 2023 11:41:15 GMT</pubDate>
            <atom:updated>2023-03-24T11:41:15.420Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sOu4uAkCA5WZlJBgPm2hGQ.png" /></figure><p>React Native’s new architecture was still considered experimental and not yet fully stable for production use. However, the React Native team had been actively working on improving and refining this new architecture, with the goal of eventually making it the default architecture for React Native projects.</p><p>You can migrate your existing React Native project to the new architecture. However, migrating to the new architecture can require some changes to your existing codebase and project structure. The migration process may also involve updating dependencies, modifying native code, and adjusting your project’s build process.</p><p>To migrate your project to the new architecture, you can follow the migration guide</p><p><a href="https://reactnative.dev/docs/new-architecture-intro">Migrating to the New Architecture · React Native</a></p><h3><strong>Current Architecture(JSC):</strong></h3><p>In React Native, the bridge is responsible for enabling communication between the JavaScript code running in the JavaScriptCore engine and the native code running on the device. The bridge creates a communication channel between the two codebases, allowing messages to be sent back and forth between them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ToSvANJVW-u_ryGDDboFLg.png" /></figure><p>In React Native, there are typically three threads that are used to manage the different aspects of the application:</p><ol><li>The UI thread (or main thread): This thread is responsible for handling user input and updating the UI components of the application. It’s also responsible for executing JavaScript code, but only one task can be executed at a time, so it’s important to keep long-running tasks off of this thread.</li><li>The JavaScript thread: This thread is responsible for running the JavaScript code that makes up the logic of the application. It’s separate from the UI thread, so it can execute long-running tasks without affecting the responsiveness of the UI.</li><li>The native module thread: This thread is used to handle communication between the JavaScript code and the native code of the device. When a native module is called from JavaScript, it’s executed on this thread.</li></ol><p>In addition to these threads, React Native also uses a “shadow thread” to manage the UI component hierarchy. This thread is used to calculate the layout and size of UI components and to manage the rendering of changes to the UI.</p><p>The way that these threads work together in a React Native application is as follows:</p><ol><li>The UI thread handles user input and updates to the UI components. When the user interacts with a component, such as by tapping a button, this thread receives the input and triggers the appropriate action.</li><li>The JavaScript thread runs the application’s business logic, such as handling network requests or updating the state of the application. When the logic requires updating the UI, the JavaScript thread sends a message to the shadow thread, which calculates the layout and size of the updated UI component.</li><li>The shadow thread sends a message back to the UI thread with the updated layout information, which triggers a redraw of the component on the screen.</li><li>If the business logic requires native functionality, such as accessing the device camera or GPS, the JavaScript thread sends a message to the native module thread, which executes the appropriate native code and returns the result back to the JavaScript thread.</li></ol><h4><strong>Drawback</strong></h4><ol><li>Asynchronous communication: The bridge uses asynchronous communication between the JavaScript and the native code of an application. While this can improve the performance of the application in some cases, it can also introduce additional complexity and make it more difficult to debug issues that arise in the application.</li><li>Unnecessary copying of data: Because the bridge communicates between the JavaScript and native code of an application, it may copy data back and forth between these two layers unnecessarily. This can lead to increased memory usage and reduced performance.</li><li>Slow data transfer: Because the bridge may need to transfer large amounts of data between the JavaScript and native code of an application, it can potentially slow down the responsiveness of the application. This can be particularly problematic in cases where real-time data is required</li></ol><h3>New Architecture(JSI):</h3><p>JSI stands for JavaScript Interface, and it is a feature in React Native that allows for a more direct interaction between JavaScript and native code. JSI (JavaScript Interface) is a low-level native module interface that allows JavaScript code to interact with native code without going through the React Native bridge. JSI is used in conjunction with Fabric, TurboModules, and Codegen to provide high-performance, efficient communication between JavaScript and native code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m3kGyD9Wp1msUx1Lb8IVRg.png" /></figure><h4>Fabric</h4><p>Fabric is a re-architecture of the React Native framework that is designed to improve performance, stability, and reliability. It is a lightweight, optimized, and extensible framework that enables high-performance layout and rendering of native UI components.</p><h4>TurboModules</h4><p>TurboModules is a module system for React Native that replaces the legacy NativeModules system. TurboModules are pre-compiled native modules that can be loaded and executed more quickly than legacy NativeModules.</p><h4>Codegen</h4><p>Codegen is a code-generation tool that generates native code for TurboModules based on a declarative specification of the module’s interface. Codegen reduces the overhead of runtime type-checking and enables more efficient communication between JavaScript and native code.</p><h4>JSI</h4><p>JSI is a low-level native module interface that allows JavaScript code to interact with native code without going through the React Native bridge. JSI enables direct communication between JavaScript and native code, reducing the overhead of marshaling and unmarshaling data between the two environments.</p><h3>Javascript Engine:</h3><p>V8 and Hermes are both JavaScript engines used in mobile app development, with V8 being primarily used in Android and Hermes being used in React Native applications. Here are some differences between V8 and Hermes:</p><ol><li>Performance: V8 is known for its high performance and is used in a variety of applications, including Google Chrome. Hermes, on the other hand, is designed specifically for mobile app development and is optimized for React Native.</li><li>Memory usage: Hermes is designed to minimize memory usage in mobile apps, which is crucial for devices with limited memory resources. V8 is more flexible in terms of memory usage, but may not be as optimized for mobile devices as Hermes.</li><li>Start-up time: Hermes has a faster start-up time compared to V8, which is important for mobile apps that need to launch quickly and provide a seamless user experience.</li><li>Garbage collection: V8 uses a generational garbage collector, while Hermes uses a concurrent garbage collector. Both approaches have their advantages and disadvantages, but the key difference is that V8’s approach may be more optimized for long-running server applications, while Hermes’ approach may be more optimized for mobile app development.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd4d212abb27" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimize Large List in React]]></title>
            <link>https://medium.com/@yasir.naeem/optimize-large-list-in-react-471e8e4d4717?source=rss-b463fd93ac3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/471e8e4d4717</guid>
            <category><![CDATA[rendering]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Yasir Naeem]]></dc:creator>
            <pubDate>Fri, 10 Mar 2023 06:20:29 GMT</pubDate>
            <atom:updated>2023-03-10T06:20:29.288Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*9h2thT1w_9py3JOXH9CqMw.jpeg" /></figure><p>When it comes to rendering large lists in React, performance can become a bottleneck. Rendering a long list of items can cause delays and slow down the user interface, making the application feel sluggish and unresponsive. However, there are ways to optimize the rendering of large lists in React to improve performance and create a better user experience. In this blog post, we will explore some strategies for optimizing large lists in React.</p><p>I am not going to use Virtualized List, PureComponent, React.memo, or any other life cycle methods normalizing your data and separating your data ids into separate states and objects in the separate state can also help optimize a large list in React.</p><p>When working with large datasets, it’s important to consider how you’re storing and accessing your data. One approach is to normalize your data, which involves breaking it up into smaller, more manageable pieces.</p><p>One way to do this is by separating your data ids into a separate state object. For example, if you have a list of items that you want to render, you can create a separate state object that stores the ids of those items.</p><p>Here’s an example of how this might look:</p><pre>const [itemIds, setItemIds] = useState([]);<br><br>// When you receive your data, extract the ids and set them in state<br>const data = [  { id: 1, name: &#39;Item 1&#39; },  { id: 2, name: &#39;Item 2&#39; },  { id: 3, name: &#39;Item 3&#39; },];<br><br>setItemIds(data.map(item =&gt; item.id));</pre><p>Separating your data ids into a separate state object can help improve performance by allowing you to only render the items that are currently visible in your list. You can use the itemIds state object to determine which items to render, and then fetch the data for those items as needed.</p><p>Additionally, you can create a separate state object for your item data, which can help further optimize your application. For example, instead of storing your entire list of items in a single state object, you can create a separate state object for each item, with the item’s id as the key</p><p>Here’s an example of how this might look:</p><pre>const [items, setItems] = useState({});<br><br>// When you receive your data, store each item in its own state object<br>const data = [  { id: 1, name: &#39;Item 1&#39; },  { id: 2, name: &#39;Item 2&#39; },  { id: 3, name: &#39;Item 3&#39; },];<br><br>const newItems = {};<br>data.forEach(item =&gt; {<br>  newItems[item.id] = item;<br>});<br><br>setItems(newItems);</pre><p>Separating your item data into separate state objects can help improve performance by allowing you to only update the data for a specific item when it changes, rather than having to re-render the entire list.</p><p>For example, let’s say you have a list of items that are stored as separate state objects with their ids as the keys:</p><pre>const [items, setItems] = useState({<br>  1: { id: 1, name: &#39;Item 1&#39;, description: &#39;This is item 1&#39; },<br>  2: { id: 2, name: &#39;Item 2&#39;, description: &#39;This is item 2&#39; },<br>  3: { id: 3, name: &#39;Item 3&#39;, description: &#39;This is item 3&#39; },<br>  // ... and so on<br>});</pre><p>If you update an item in this list, React will only re-render that item, rather than the entire list. For example, if you update item 2’s name, only that item will be re-rendered:</p><pre>// Update item 2&#39;s name<br>const updatedItem = { ...items[2], name: &#39;Updated Item 2&#39; };<br>setItems({<br>  ...items,<br>  [updatedItem.id]: updatedItem,<br>});</pre><p>This is because React’s rendering process is optimized to only update the parts of the UI that have changed. By breaking your data into smaller, more manageable pieces, you can help ensure that only the relevant parts of your UI are updated when changes occur.</p><p>In summary, separating your item data into separate state objects by id can help ensure that only the relevant item is re-rendered when it changes, rather than the entire list. This can help improve the performance of your application and create a better user experience</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=471e8e4d4717" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>