颤振稳定性叶瓣图_颤振性能优化

2024-03-03 09:59

本文主要是介绍颤振稳定性叶瓣图_颤振性能优化,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

颤振稳定性叶瓣图

Ever wondered how flutter handles all your UI building and events like Futures, taps, etc.. on a single thread( yes it does all that on a single thread 😮😮😮 until and unless explicitly done).

曾经想知道flutter如何在单个线程上处理所有UI构建和事件,例如Future,taps等。(是的,它在单个线程上完成所有操作😮😮😮直到并且除非明确完成)。

什么是线程/隔离? (What is Thread/Isolates ?)

Thread is an independent process that has its own chunk of memory and executes the given instructions on that memory , It can work parallelly with other threads hence can reduce execution time of multiple process on a single thread .

线程是一个独立的进程,具有自己的内存块并在该内存上执行给定的指令。它可以与其他线程并行工作,因此可以减少单个线程上多个进程的执行时间。

Let’s understand this with an example :

让我们通过一个例子来理解这一点:

In Fps games like counter strike, Call of duty, etc. you can see that as soon as you fire a weapon few tasks executes simultaneously like playing of bullet sound, change of bullet count and reduction in opponent health , All these things happens parallelly these are basically threads which execute parallelly and execute their task on separate isolates(isolates and threads can be used interchangeably as isolate is a Dart way of multi threading more on that below) which have its own memory.

在Fps游戏中,例如反恐精英,使命召唤等,您可以看到,一旦发射武器,几乎没有同时执行的任务,例如弹奏子弹声,改变子弹数和减少对手的生命值,所有这些并行发生基本上是并行执行并在单独的隔离上执行其任务的线程(隔离和线程可以互换使用,因为隔离是Dart在下面的更多内容中介绍的多线程方法),它具有自己的内存。

演示地址

Languages like JAVA and C++ Share Their heap memory with threads, but in case of flutter, every isolate has its own memory and works independently. As it has its own private space this memory doesn’t require locking, as if a thread finishes its task it already means that the thread has finished utilizing its memory space and then that memory can go for garbage collection.

诸如JAVA和C ++之类的语言与线程共享它们的堆内存,但是在出现混乱的情况下,每个隔离都有自己的内存并且可以独立工作。 由于该内存具有自己的私有空间,因此不需要锁定,就好像一个线程完成了它的任务一样,这意味着该线程已经完成了对它的内存空间的利用,然后该内存可以用于垃圾回收了。

To maintain these benefits flutter has a separate memory for every isolate(Flutter way of multi-threading) that’s why they are called isolate 🙂.

为了保持这些好处,flutter为每个隔离(Flutter的多线程方式)都有一个单独的内存,这就是为什么它们被称为isolate🙂。

Learn more about isolates below.

在下面了解有关隔离株的更多信息。

演示地址

它对我有什么帮助?在哪里应该使用隔离/线程? (How can it be helpful to me and where should I use isolates/Threads?)

何时使用隔离/线程? (When to use isolates/threads ?)

There are a few situations where isolates can be very handy.

在某些情况下,隔离很方便。

  1. Let say you want to execute a network call and you want to process that data that you just received . and that data contains about million records that alone will hang your UI.

    假设您要执行网络呼叫,并且要处理刚收到的数据。 并且这些数据包含大约一百万条记录,仅此一项就会挂起您的UI。
  2. You have some image processing tasks that you want to do on-device these kinds of tasks are highly computational as they have to deal with lots of number crunching operations which may lead to frozen UI or legginess in UI.

    您有一些要在设备上执行的图像处理任务,这些类型的任务需要大量的计算,因为它们必须处理大量的数字运算操作,这可能会导致UI冻结或UI出现问题。

So to conclude when to use isolates, We should use them whenever you think there is a lot of computation that needs to be offloaded from the main thread.

因此,总结一下何时使用隔离符,只要您认为需要从主线程中卸载大量计算,就应该使用它们。

如何使用隔离株? (How to use isolates ?)

Flutter team has designed a very elegant and abstract way of using isolates/threads in a flutter, Using compute we can do the same task which isolates does but in a more cleaner and abstract way. Let’s take a look at the flutter compute function.

Flutter团队设计了一种在flutter中使用隔离/线程的非常优雅和抽象的方法。使用计算,我们可以执行与isolates相同的任务,但使用的方法更加简洁和抽象。 让我们看一下Flutter 计算功能。

Syntax:

句法:

var getData = await compute(function,parameter);

Compute function takes two parameters :

计算功能采用两个参数:

  1. A future or a function but that must be static (as in dart threads does not share memory so they are class level members not object level).

    未来或功能,但必须是静态的(如dart线程不共享内存,因此它们是类级别的成员,而不是对象级别的成员)。
  2. Argument to pass into the function, To send multiple arguments you can pass it as a map(as it only supports single argument).

    要传递给函数的参数,要发送多个参数,可以将其作为映射传递(因为它仅支持单个参数)。

compute function returns a Future which if you want can store into a variable and can provide it into a future builder.

计算函数返回一个Future,如果需要,可以将其存储到变量中并将其提供给future构建器。

Let’s start by analyzing a sample problem:

让我们开始分析一个样本问题:

import 'dart:io';import 'package:flutter/material.dart';class With10SecondDelay extends StatelessWidget {runningFunction() {int sum = 0;for (int i = 1; i <= 10; i++) {sleep(Duration(seconds: 1));print(i);sum += i;}return "total sum is $sum";}pauseFunction() {//pause function is not asyncprint(runningFunction());}@overrideWidget build(BuildContext context) {pauseFunction();return Material(child: Center(child: Center(child: Text("Tnx for waiting 10 seconds : check console for response",style: TextStyle(fontSize: 50,),),),),);}
}

In the above code pausefunction() is called just below the build method which pauses the execution of code for 10 seconds. And because of that when you try to navigate to this page from a previous one there will be a delay of ten seconds before our page gets pushed on to the widget tree.

在上面的代码中,在build方法正下方调用了pausefunction(),该方法将代码的执行暂停10秒钟。 因此,当您尝试从上一个页面导航到该页面时,将有十秒钟的延迟,然后我们的页面被推到小部件树上。

We can try to resolve this issue by using async.

我们可以尝试使用异步解决此问题。

pauseFunction() async {//pause function is asyncprint(runningFunction());}

As you can see now we have declared our pause function as async even doing this will not help

如您现在所见,我们已经将暂停功能声明为异步,即使这样做也无济于事

As async in dart is basically puts our code in ideal until there is something to compute so it seems to us that dart is executing these on a different thread but actually it’s just waiting for some event to occur in that async function.

由于dart中的async基本上使我们的代码处于理想状态,直到可以进行计算为止,因此在我们看来dart在不同的线程上执行这些操作,但实际上它只是在等待该async函数中发生的事件。

More on async below :

以下是有关异步的更多信息:

演示地址

Let’s solve the above issue using compute.

让我们使用compute解决上述问题。

import 'dart:io';import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';class ComputeWith10SecondDelay extends StatelessWidget {static Future<String> runningFunction(String str) async {int sum = 0;for (int i = 1; i <= 10; i++) {await Future.delayed(Duration(seconds: 1));print(i);sum += i;}return "Sum is : " + sum.toString() + str;}pauseFunction() async {print(await compute(runningFunction," This is an argument")); //storing data of copute result}@overrideWidget build(BuildContext context) {pauseFunction();return Material(child: Center(child: Center(child: Text("Wow , it saved my 10 seconds : check console for response",style: TextStyle(fontSize: 50,),),),),);}
}

In the above code, we basically passed our function in compute() function and that creates a separate isolate to handle the task and our main UI will still run without any delay (check the debug console for response ).

在上面的代码中,我们基本上将函数传递给了compute()函数,并创建了一个单独的隔离来处理任务,我们的主UI仍将无任何延迟地运行(请检查调试控制台以获取响应)。

Summary:

摘要:

  1. Dart is by default executes all its code on a single-threaded.

    默认情况下,Dart是在单线程上执行其所有代码。
  2. Every function and every async-await calls work only on the main thread(until and unless specified).

    每个函数和每个async-await调用仅在主线程上起作用(直到指定,除非指定)。
  3. We can create multiple threads using compute( Future function/normal function, argument).

    我们可以使用compute(Future function / normal function,arguments)创建多个线程。
  4. You can use compute for executing network calls, performing number-crunching calculations, image processing, etc.

    您可以使用计算来执行网络呼叫,执行数字运算,图像处理等。

This is all about compute to learn more about isolates (the underlying architecture of computing function) check out isolate .

这就是关于计算的全部内容,以了解有关隔离的更多信息(计算功能的基础体系结构)签出隔离 。

Thanks for reading this article.

感谢您阅读本文。

If you find it interesting Please Clap! and if you found anything wrong please let me know I would appreciate it for your contribution.

如果您觉得有趣,请拍手! 如果您发现任何错误,请告诉我,感谢您的贡献。

Check out full code at FlutterDevs GitHub.

在以下位置查看完整代码 FlutterDevs GitHub。

FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, Twitter, and LinkedIn for any flutter related queries.

FlutterDevs的Flutter开发人员团队可构建高质量且功能丰富的应用程序。 根据您的要求,每小时或全时为您的跨平台Flutter移动应用程序项目雇用flutter开发人员 ! 您可以在Facebook , GitHub , Twitter和LinkedIn 上与我们联系,以获取任何与抖动相关的查询。

We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences!.

我们欢迎您提供反馈,并希望您分享使用#FlutterDevs所做的工作 。 我们非常高兴看到您如何使用Flutter建立美好的交互式Web体验!

Image for post

翻译自: https://medium.com/flutterdevs/flutter-performance-optimization-17c99bb31553

颤振稳定性叶瓣图


http://www.taodudu.cc/news/show-8479333.html

相关文章:

  • 双路颤振频率Hz可设置比例阀放大器
  • 深度聚类paper汇总
  • paperwithcode
  • AAAI2021 accepted paper list
  • 使用Tex 撰写paper-TexStudio设置默认字体样式大小等
  • Raphael学习之Paper常用API(四)
  • 如何写paper
  • Paper:txyz_ai(一款帮助科研人员阅读PDF论文ChatGPT利器)的简介、安装、使用方法之详细攻略
  • 抑郁症康复日记
  • 计算机抑郁症与干涉相关的,抑郁症
  • matlab 自带的数据集fisheriris
  • 【文末福利】为什么我们要掌握Linux系统编程?
  • 什么是TCP的混合型自时钟
  • 炮打洋鬼子创作总结
  • oracle 过滤字段中的中文,不再洋不洋土不土
  • field list什么意思_闲话Python之range()到底是个什么玩意儿
  • AI全栈大模型工程师(二十二)什么是模型训练
  • 什么是mysql锁_简单理解MySQL锁
  • 什么是MAS : 一种目标管理工具和方法
  • 什么是接口API
  • python函数一般不能_Python程序中对一个函数的调用不能出现在该函数的定义之前...
  • 打字练习软件 Type Fu mac中文版技能介绍
  • 打字练习(Python代码模拟打字练习软件效果)
  • 增长率超60%,工业机器人进入新一轮爆发期!
  • 数据结构与算法-动态规划-机器人达到指定位置方法数
  • 机器人学习之项目- Project5:KUKA Robot Challenge(一)
  • 机器人学习-路径规划实验(一)
  • 机器人编程(Robot Programming)学习笔记一
  • 非夕机器人配合笔记
  • Flexiv发布首个自适应机械臂,带来第三代机器人技术
  • 这篇关于颤振稳定性叶瓣图_颤振性能优化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



    http://www.chinasem.cn/article/769273

    相关文章

    从原理到实战解析Java Stream 的并行流性能优化

    《从原理到实战解析JavaStream的并行流性能优化》本文给大家介绍JavaStream的并行流性能优化:从原理到实战的全攻略,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的... 目录一、并行流的核心原理与适用场景二、性能优化的核心策略1. 合理设置并行度:打破默认阈值2. 避免装箱

    Python实战之SEO优化自动化工具开发指南

    《Python实战之SEO优化自动化工具开发指南》在数字化营销时代,搜索引擎优化(SEO)已成为网站获取流量的重要手段,本文将带您使用Python开发一套完整的SEO自动化工具,需要的可以了解下... 目录前言项目概述技术栈选择核心模块实现1. 关键词研究模块2. 网站技术seo检测模块3. 内容优化分析模

    Java实现复杂查询优化的7个技巧小结

    《Java实现复杂查询优化的7个技巧小结》在Java项目中,复杂查询是开发者面临的“硬骨头”,本文将通过7个实战技巧,结合代码示例和性能对比,手把手教你如何让复杂查询变得优雅,大家可以根据需求进行选择... 目录一、复杂查询的痛点:为何你的代码“又臭又长”1.1冗余变量与中间状态1.2重复查询与性能陷阱1.

    Python内存优化的实战技巧分享

    《Python内存优化的实战技巧分享》Python作为一门解释型语言,虽然在开发效率上有着显著优势,但在执行效率方面往往被诟病,然而,通过合理的内存优化策略,我们可以让Python程序的运行速度提升3... 目录前言python内存管理机制引用计数机制垃圾回收机制内存泄漏的常见原因1. 循环引用2. 全局变

    深度剖析SpringBoot日志性能提升的原因与解决

    《深度剖析SpringBoot日志性能提升的原因与解决》日志记录本该是辅助工具,却为何成了性能瓶颈,SpringBoot如何用代码彻底破解日志导致的高延迟问题,感兴趣的小伙伴可以跟随小编一起学习一下... 目录前言第一章:日志性能陷阱的底层原理1.1 日志级别的“双刃剑”效应1.2 同步日志的“吞吐量杀手”

    Python多线程应用中的卡死问题优化方案指南

    《Python多线程应用中的卡死问题优化方案指南》在利用Python语言开发某查询软件时,遇到了点击搜索按钮后软件卡死的问题,本文将简单分析一下出现的原因以及对应的优化方案,希望对大家有所帮助... 目录问题描述优化方案1. 网络请求优化2. 多线程架构优化3. 全局异常处理4. 配置管理优化优化效果1.

    MySQL中优化CPU使用的详细指南

    《MySQL中优化CPU使用的详细指南》优化MySQL的CPU使用可以显著提高数据库的性能和响应时间,本文为大家整理了一些优化CPU使用的方法,大家可以根据需要进行选择... 目录一、优化查询和索引1.1 优化查询语句1.2 创建和优化索引1.3 避免全表扫描二、调整mysql配置参数2.1 调整线程数2.

    Java慢查询排查与性能调优完整实战指南

    《Java慢查询排查与性能调优完整实战指南》Java调优是一个广泛的话题,它涵盖了代码优化、内存管理、并发处理等多个方面,:本文主要介绍Java慢查询排查与性能调优的相关资料,文中通过代码介绍的非... 目录1. 事故全景:从告警到定位1.1 事故时间线1.2 关键指标异常1.3 排查工具链2. 深度剖析:

    深入解析Java NIO在高并发场景下的性能优化实践指南

    《深入解析JavaNIO在高并发场景下的性能优化实践指南》随着互联网业务不断演进,对高并发、低延时网络服务的需求日益增长,本文将深入解析JavaNIO在高并发场景下的性能优化方法,希望对大家有所帮助... 目录简介一、技术背景与应用场景二、核心原理深入分析2.1 Selector多路复用2.2 Buffer

    SpringBoot利用树形结构优化查询速度

    《SpringBoot利用树形结构优化查询速度》这篇文章主要为大家详细介绍了SpringBoot利用树形结构优化查询速度,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一个真实的性能灾难传统方案为什么这么慢N+1查询灾难性能测试数据对比核心解决方案:一次查询 + O(n)算法解决