<?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>DEV Community: 7oby</title>
    <description>The latest articles on DEV Community by 7oby (@7oby).</description>
    <link>https://dev.to/7oby</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%2F2199269%2Fe41a494b-8434-440c-ae54-8779d681fff6.png</url>
      <title>DEV Community: 7oby</title>
      <link>https://dev.to/7oby</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/7oby"/>
    <language>en</language>
    <item>
      <title>Flutter Offline Data Storage: Exploring Differents Solutions</title>
      <dc:creator>7oby</dc:creator>
      <pubDate>Mon, 10 Mar 2025 09:59:44 +0000</pubDate>
      <link>https://dev.to/7oby/flutter-offline-data-storage-exploring-differents-solutions-25ma</link>
      <guid>https://dev.to/7oby/flutter-offline-data-storage-exploring-differents-solutions-25ma</guid>
      <description>&lt;p&gt;Flutter’s out here flexing as one of the top, if not THE top, frameworks for building cross-platform mobile apps. It makes it easy to create apps that perform at their best and keep your users happy with smooth experiences.&lt;/p&gt;

&lt;p&gt;Now, when we talk about user experience, there’s one thing that really matters — making sure your app works even when users are offline. Yeah, you need to make sure they can still access the important stuff in your app even when the Wi-Fi’s acting up or they’re somewhere with bad signal.&lt;/p&gt;

&lt;p&gt;If you didn’t know, adding offline features to your app is gonna:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Boost the User Experience&lt;/strong&gt;: Users can still get into your app and use its features without needing a strong internet connection. It makes your app more reliable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Make Your App Faster&lt;/strong&gt;: Storing data locally means your app loads up quicker and runs smoother.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Help Users in Low Connectivity Areas: People with bad or no internet still get to use your app, which makes it super useful in a bunch of places.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cut Data Costs&lt;/strong&gt;: Users save on data by using stored info instead of constantly re-downloading stuff.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Keep Things Running Smooth&lt;/strong&gt;: Apps like note-taking or e-commerce can still run without any interruptions — users can add, edit, and save stuff while offline.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Get People Coming Back&lt;/strong&gt;: If your app works well offline, users are more likely to stick around and use it more.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Make It Reliable&lt;/strong&gt;: Offline mode means less chance of interruptions, so users can count on your app when they need it most.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Give Users More Freedom&lt;/strong&gt;: They can use the app whenever, whether they’re traveling, in a meeting, or in a spot with bad connection.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There’re many ways to handle offline storage in Flutter. From simple stuff like key-value pairs with Shared Preferences to full-on databases like SQLite, or lightweight NoSQL ones like Hive and ObjectBox.&lt;/p&gt;

&lt;p&gt;In this article, we’re gonna give you a quick rundown on each. But trust, we’ll dive deeper into them in upcoming posts — explaining what makes each of them tick and when to use ‘em.&lt;/p&gt;

&lt;p&gt;So, let’s jump right in…&lt;/p&gt;

&lt;h2&gt;
  
  
  Shared Preferences Package
&lt;/h2&gt;

&lt;p&gt;Shared Preferences is like a simple locker where you can store small data, like settings or app states. It’s perfect for lightweight storage, like saving the user’s theme, language settings, or login tokens. It’s easy to set up and doesn’t require you to deal with complicated databases.&lt;/p&gt;

&lt;p&gt;Here’s how you use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:shared_preferences/shared_preferences.dart';

// Save a value
Future&amp;lt;void&amp;gt; savePreference(String key, String value) async {
 final prefs = await SharedPreferences.getInstance();
 await prefs.setString(key, value);
}

// Get a value
Future&amp;lt;String?&amp;gt; getPreference(String key) async {
 final prefs = await SharedPreferences.getInstance();
 return prefs.getString(key);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easy to set up for storing simple stuff.&lt;/li&gt;
&lt;li&gt;Lightweight and fast.&lt;/li&gt;
&lt;li&gt;Works cross-platform with a consistent API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Not built for complex data or big datasets.&lt;/li&gt;
&lt;li&gt;Only stores basic types like strings, ints, and booleans.&lt;/li&gt;
&lt;li&gt;No fancy query options for more advanced needs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  SQLite
&lt;/h2&gt;

&lt;p&gt;SQLite is like a mini database you can embed directly into your app. It’s great for handling large, structured data with relationships. It’s good when you need to manage a lot of data and want to run SQL queries to fetch and manipulate it.&lt;/p&gt;

&lt;p&gt;Check this out for basic SQLite operations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';

// Setup the DB
Future&amp;lt;Database&amp;gt; initializeDB() async {
 String path = join(await getDatabasesPath(), 'example.db');
 return openDatabase(
   path,
   onCreate: (database, version) async {
     await database.execute(
       "CREATE TABLE items(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)",
     );
   },
   version: 1,
 );
}

// Insert a new item
Future&amp;lt;void&amp;gt; insertItem(String name) async {
 final Database db = await initializeDB();
 await db.insert('items', {'name': name});
}

// Get all items
Future&amp;lt;List&amp;lt;Map&amp;lt;String, dynamic&amp;gt;&amp;gt;&amp;gt; retrieveItems() async {
 final Database db = await initializeDB();
 return await db.query('items');
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Good for complex queries and handling relationships between data.&lt;/li&gt;
&lt;li&gt;Handles big data sets well.&lt;/li&gt;
&lt;li&gt;Transactions keep your data safe and secure.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A little more setup than simple storage options.&lt;/li&gt;
&lt;li&gt;Not needed if you only need to store small amounts of data.&lt;/li&gt;
&lt;li&gt;You gotta know SQL, which might be a challenge for beginners.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Hive
&lt;/h2&gt;

&lt;p&gt;Hive is a fast and simple NoSQL database made for Flutter. It’s light, quick, and great for storing data without the need for SQL. You can store basic data types, lists, and maps, and it handles read/write operations like a champ.&lt;/p&gt;

&lt;p&gt;Here’s how you can get started with Hive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';

void main() async {
 await Hive.initFlutter();
 var box = await Hive.openBox('myBox');
// Save data
 await box.put('name', 'Flutter Developer');
// Retrieve data
 String name = box.get('name') ?? 'No Name';
 print(name); // Output: Flutter Developer
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Super fast, making it great for performance-sensitive apps.&lt;/li&gt;
&lt;li&gt;Simple and easy to use.&lt;/li&gt;
&lt;li&gt;Supports lists and maps, making it more flexible.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No relational features like SQLite.&lt;/li&gt;
&lt;li&gt;Changing your data structure can be tricky.&lt;/li&gt;
&lt;li&gt;Limited querying options.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Drift (Moor)
&lt;/h2&gt;

&lt;p&gt;Drift (previously Moor) is like a turbocharged SQLite. It lets you work with SQL while adding cool features like real-time updates and automatic code generation. It’s great for apps with structured data and when you need your app to react to data changes in real-time.&lt;/p&gt;

&lt;p&gt;Here’s how you set it up:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:drift/drift.dart';
import 'package:drift/native.dart';

// Define the structure
@DataClassName('Item')
class Items extends Table {
 IntColumn get id =&amp;gt; integer().autoIncrement()();
 TextColumn get name =&amp;gt; text()();
}

// Create the database
@DriftDatabase(tables: [Items])
class AppDatabase extends _$AppDatabase {
 AppDatabase() : super(NativeDatabase.memory());
 Future&amp;lt;List&amp;lt;Item&amp;gt;&amp;gt; getAllItems() =&amp;gt; select(items).get();
 Future insertItem(Insertable&amp;lt;Item&amp;gt; item) =&amp;gt; into(items).insert(item);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Type-safe, so it avoids bugs when working with data.&lt;/li&gt;
&lt;li&gt;Real-time updates, so the app UI stays fresh.&lt;/li&gt;
&lt;li&gt;Built-in migrations to help with schema changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Takes some time to get used to if you’re new to reactive programming.&lt;/li&gt;
&lt;li&gt;Setup can be more complex than simpler storage methods.&lt;/li&gt;
&lt;li&gt;Code generation and extra dependencies add a bit of overhead.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  ObjectBox
&lt;/h2&gt;

&lt;p&gt;ObjectBox is a high-performance NoSQL database built for mobile and IoT apps. It’s fast as hell, and you work directly with Dart objects, so there’s no need to convert stuff into JSON. It’s ideal for real-time apps or anything needing quick access to a lot of data.&lt;/p&gt;

&lt;p&gt;Here’s how you set it up:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:objectbox/objectbox.dart';
import 'package:objectbox_flutter_libs/objectbox_flutter_libs.dart';

// Define the data model
@Entity()
class Item {
 int id;
 String name;
 Item({this.id = 0, required this.name});
}

// Create the ObjectBox store
void main() async {
 final store = await openStore();
// Save an object
 final item = Item(name: 'Flutter Developer');
 store.box&amp;lt;Item&amp;gt;().put(item);
// Get all items
 final items = store.box&amp;lt;Item&amp;gt;().getAll();
 items.forEach((item) {
   print('Item: ${item.name}');
 });
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Super fast for large datasets.&lt;/li&gt;
&lt;li&gt;Directly works with Dart objects — no conversion needed.&lt;/li&gt;
&lt;li&gt;Built-in reactive programming support.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NoSQL, so not ideal for complex queries.&lt;/li&gt;
&lt;li&gt;Limited docs and community support.&lt;/li&gt;
&lt;li&gt;Might take time to get used to if you’re not familiar with object-oriented databases.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;When it comes to choosing offline storage in Flutter, here’s what I recommend:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For simple preferences and settings: Go with Shared Preferences.&lt;/li&gt;
&lt;li&gt;For fast data storage: Try Hive.&lt;/li&gt;
&lt;li&gt;For structured data with relationships: Go for Drift (Moor).&lt;/li&gt;
&lt;li&gt;For high-performance apps: ObjectBox is the move.&lt;/li&gt;
&lt;li&gt;For complex data and queries: SQLite is the best.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At the end of the day, it all comes down to what kind of app you’re building. Choose wisely based on your needs, and you’ll be good to go.&lt;/p&gt;

&lt;p&gt;Follow me! And stay tuned for future posts where we’ll break each of these options down in detail and show you exactly how to integrate them into your apps.&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>performance</category>
      <category>mobile</category>
    </item>
    <item>
      <title>CPUs, GPUs, TPUs, DPUs, why?</title>
      <dc:creator>7oby</dc:creator>
      <pubDate>Mon, 02 Dec 2024 15:15:21 +0000</pubDate>
      <link>https://dev.to/7oby/cpus-gpus-tpus-dpus-why-1p62</link>
      <guid>https://dev.to/7oby/cpus-gpus-tpus-dpus-why-1p62</guid>
      <description>&lt;p&gt;For me (I mean at that time), things were as simple as this: There would be only two types of Processing Units: GPU and CPU. CPUs are the standard and GPUs are exclusively used for everything graphics related (like video games).&lt;/p&gt;

&lt;p&gt;But then I slid into the Machine learning field and started hearing my pairs talking about TPU and sometimes about a mysterious DPU. Sometimes they are even struggling deciding which one to use to train their Machine learning models. &lt;/p&gt;

&lt;p&gt;Which ones are those two again? And how are they different from the other ones.&lt;br&gt;
I had to find answers to those questions. So I did some googling on the matter and found out &lt;strong&gt;MY WHOLE LIFE WAS A LIE&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;CPUs, GPUs, TPUs, DPUs, none of those is technically better than the other. But simply each of them is built or optimized for a particular purpose which it excels at, compared to the rest.&lt;/p&gt;

&lt;h2&gt;
  
  
  So what is the purpose of having a CPU?
&lt;/h2&gt;

&lt;p&gt;First you have to understand that Processing Units have what we call cores and each of those cores can perform only one task at the same time. So the more a PU has cores, the more tasks it is able to perform in parallel (i.e at the same time).&lt;/p&gt;

&lt;p&gt;From far, CPUs have always been the best suited for the most logic heavy computer operations you can think of. That's because the high performance cores of a CPU are optimized for sequential (step by step) processing and low-latency branching.&lt;br&gt;
So CPUs are the best option when it comes to complex operations like &lt;strong&gt;Database Query Execution, Operating System Management, Compiling Code, Encryption and Decryption, Data Serialization/Deserialization, File System Operations, Real-Time System Operations, Error Detection and Correction, Simulation of Rule-Based Systems&lt;/strong&gt;, etc., or any task requiring extensive &lt;strong&gt;if-else or switch-case branching logic&lt;/strong&gt;, which must be executed &lt;strong&gt;step-by-step&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The annoying thing about sequential processing though is that it can take time, so much time… especially for massive tasks like graphics rendering.&lt;br&gt;
Imagine having to rely on a few CPU’s cores for a high graphics video game like Cyberpunk 2077. It would lag so much that you’d never want to play a video game in your life, lol.&lt;br&gt;
Around millions of CPUs cores would be needed to render the graphics of such a game in real time avoiding any lagging and achieving an ideal User Experience.&lt;/p&gt;

&lt;p&gt;“Why don't we add more cores to the CPU then?” You may ask.&lt;br&gt;
Well, like we (implicitly) stated earlier, the cores of a CPU are very large and resource-intensive having quite a complex architecture and making the amount that can fit on a chip very limited (typically 4–32). Scaling such cores would increase power consumption and heat generation, leading to diminishing returns.&lt;/p&gt;

&lt;p&gt;But there is good news! Many computer operations like graphics rendering involve tasks that are highly repetitive and can be broken down into many smaller, independent operations that do not require a lot of branching or conditional logic.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If we cannot scale the number of the large cores, How about building tinier cores of simpler architecture so that we could gather thousands of them to complete repetitive tasks in parallel? That would solve many problems like the graphics rendering one. Yes, and we would call that the Graphic Processing Unit.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The need of a Graphic Processing Unit
&lt;/h2&gt;

&lt;p&gt;Enter the Graphics Processing Unit (GPU), a chip built for parallel computing. While CPUs may have up to 24 cores, modern GPUs like NVIDIA's RTX 4080 boast nearly 10,000 cores. Each core can perform a computation simultaneously. &lt;br&gt;
And while they were originally built to solve the graphics rendering problem (calculating lights, shadows, and textures in real-time), the massive amounts of cores of GPUs and their parallelism make them an option for other tasks like &lt;br&gt;
AI and deep learning (performing massive matrix multiplications for training models)&lt;/p&gt;

&lt;h2&gt;
  
  
  Then Why the TPU?
&lt;/h2&gt;

&lt;p&gt;The Tensor Processing Unit (TPU) is a specialized chip designed for deep learning. Created by Google in 2016, TPUs focus on tensor operations (like matrix multiplication) required for training AI models. Unlike GPUs, TPUs eliminate the need to access shared memory or registers, making them far more efficient for neural network training.&lt;/p&gt;

&lt;p&gt;If you’re working with massive datasets or training large models, TPUs can save you significant time and resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  DPUs: The Data Center Workhorse
&lt;/h2&gt;

&lt;p&gt;The Data Processing Unit (DPU) is the newest member of the computing family, optimized for data-intensive tasks in cloud environments. These chips handle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Networking: Packet processing, routing, and security.&lt;/li&gt;
&lt;li&gt;Data storage: Compression and encryption.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;DPUs offload these tasks from CPUs, allowing the CPU to focus on general-purpose computing. While you won’t find a DPU in your laptop, they are essential for modern data centers where efficiency is paramount.&lt;/p&gt;

&lt;h2&gt;
  
  
  That's it!
&lt;/h2&gt;

&lt;p&gt;If you didn't, now you know the difference between those proccessing units.CPUs remain the backbone of general-purpose computing, excelling in logic-heavy, sequential tasks. GPUs, with their massively parallel architecture, dominate in rendering, machine learning, and any workload requiring high-throughput computations. TPUs are purpose-built for deep learning, offering unmatched efficiency in training and inference for neural networks. DPUs, on the other hand, cater to data-centric operations, offloading tasks like networking and storage from CPUs to boost efficiency in large-scale data centers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next article,
&lt;/h2&gt;

&lt;p&gt;on this subject will be for machine learning engineers, where we will discuss how to choose the right processing unit for your AI workload. We'll explore the roles of GPUs, TPUs, and CPUs in training and inference, compare their performance, cost, and scalability, and dive into practical tips for optimizing your machine learning pipelines for maximum efficiency.&lt;br&gt;
&lt;strong&gt;Keep in touch!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>cpu</category>
      <category>gpu</category>
      <category>deeplearning</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
