Alamofire 序列化太慢了

     2023-02-24     305

关键词:

【中文标题】Alamofire 序列化太慢了【英文标题】:Alamofire Serialization is Too Slow 【发布时间】:2018-02-13 21:27:43 【问题描述】:

由于某种原因,我需要很长时间进行序列化。我正在使用 Alamofire 和 ObjectMapper 来处理请求响应并将数据反序列化为对象。

这是我发送的请求:

Alamofire.request(Constants.apiRequests.paloozas, method: .get, parameters: params, headers: HeaderManager.sharedInstance.authHeader!).validate().responseObject  (response: DataResponse<PaginatedPaloozas>)
    // handle response

这是 PaginatedPaloozas 对象:

struct PaginatedPaloozas: Mappable 

    var meta: PageMetaData?
    var paloozas: [Palooza]?

    init?(map: Map)  

    mutating func mapping(map: Map) 
        self.meta <- map[Constants.PaginatedPaloozas.meta]
        self.paloozas <- map[Constants.PaginatedPaloozas.paloozas]
    


这是我的 Palooza 对象:

struct Palooza: Mappable 

var id: Int!
var startingLocation: Place!
var endingLocation: Place!
var startTime: Date!
var endTime: Date?
var note: String?
var perPersonPrice: String!
var seats: Int!
var chat: String?
var completedAt: Date?
var numSeatsAvailable: Int!
var distance: Float?
var bookingFee: String!
var totalPrice: String!
var status: PaloozaStatus!
var code: String?
var involvement: Involvement!
var bookings: [Booking]?
var owner: Owner?

enum PaloozaStatus: String 
    case pending = "pending"
    case inProgress = "in_progress"
    case cancelled = "cancelled"
    case completed = "completed"


enum Involvement: String 
    case owner = "owner"
    case presenter = "presenter"
    case none = "none"


init?(map: Map)  

mutating func mapping(map: Map) 
    self.id <- map[Constants.Palooza.id]
    self.startingLocation <- map[Constants.Palooza.startingLocation]
    self.endingLocation <- map[Constants.Palooza.endingLocation]
    self.startTime <- (map[Constants.Palooza.startTime], CustomDateTransform())
    self.endTime <- (map[Constants.Palooza.returnTime], CustomDateTransform())
    self.note <- map[Constants.Palooza.note]
    self.perPersonPrice <- map[Constants.Palooza.perPersonPrice]
    self.seats <- map[Constants.Palooza.seats]
    self.chat <- map[Constants.Palooza.chat]
    self.completedAt <- (map[Constants.Palooza.completedAt], CustomDateTransform())
    self.numSeatsAvailable <- map[Constants.Palooza.numSeatsAvailable]
    self.distance <- map[Constants.Palooza.distance]
    self.bookingFee <- map[Constants.Palooza.bookingFee]
    self.totalPrice <- map[Constants.Palooza.totalPrice]
    self.status <- (map[Constants.Palooza.status], EnumTransform<PaloozaStatus>())
    self.code <- map[Constants.Palooza.code]
    self.involvement <- (map[Constants.Palooza.involvement], EnumTransform<Involvement>())
    self.bookings <- map[Constants.Palooza.bookings]
    self.owner <- map[Constants.Palooza.owner]



我只有 5 个 paloozas,序列化需要 10 秒。我尝试在 Alamofire 请求中使用不同的队列,但没有任何区别。请帮我加快这个过程。

【问题讨论】:

【参考方案1】:

事实证明,我正在减慢序列化过程,因为在此过程中我试图从 URL 中获取 UIImage。我希望这可以帮助像我这样犯愚蠢错误的人哈哈。

【讨论】:

【参考方案2】:
I would already be about the connection and server problem if network speed is 
slow. Try using a different endpoint from a different server to test the 
speed.If its faster then the problem is on your server. Since your 
implementation is correct then definitely it is server problem. alamofire has 
nothing to do on handling the issue if the problem is on the server or 
connection.

【讨论】:

for循环太慢了

】for循环太慢了【英文标题】:Forloopistooslow【发布时间】:2016-01-0113:01:38【问题描述】:我有以下代码:varCombinatorics=require(\'js-combinatorics\');varfs=require(\'fs\');cp=Combinatorics.cartesianProduct(["4","@","/\\\\","/-\\\\","^","∂","λ","α","(!" 查看详情

iPad 中的洪水填充太慢了

】iPad中的洪水填充太慢了【英文标题】:FloodfillinginiPadtooslow【发布时间】:2011-05-0901:19:28【问题描述】:我在iPad上为我的一个着色应用程序使用洪水填充。该应用程序基本上在图像的黑线内填充颜色,我可以毫无问题地做到这... 查看详情

InAppReview : SKStoreReviewController 太慢了

】InAppReview:SKStoreReviewController太慢了【英文标题】:InAppReview:SKStoreReviewControllerSoSlow【发布时间】:2017-09-2213:03:59【问题描述】:使用SKStoreReviewController进行inAppReview需要时间,直到出现提示,有什么方法可以让它显示得更快?另... 查看详情

插入 WStandardItemModel 太慢了

】插入WStandardItemModel太慢了【英文标题】:InsertinginaWStandardItemModelistooslow【发布时间】:2011-07-0417:59:53【问题描述】:我正在开发一个基于WT构建的应用程序。我们遇到了性能问题,因为它必须在与WStandardItemModel关联的WTableView中... 查看详情

Ucanaccess 太慢了

】Ucanaccess太慢了【英文标题】:Ucanaccessistooslow【发布时间】:2016-04-2708:03:07【问题描述】:我已正确添加了所有必要的JARS:Ucanaccess3.0.4commons-lang-2.6commons-logging-1.1.1hsqldbdjackcess-2.1.3我的数据库是100MB。仅使用Jacksess时,相同的查... 查看详情

为啥使用 information_schema 太慢了?

】为啥使用information_schema太慢了?【英文标题】:Whyisusinginformation_schematoomuchslow?为什么使用information_schema太慢了?【发布时间】:2017-02-2607:34:33【问题描述】:这是我的代码://dbssize$sql=\'SELECTtable_schemaDB_Name,Round(Sum(data_length+inde... 查看详情

获取数百万条记录太慢了

】获取数百万条记录太慢了【英文标题】:FetchingMillionsRecordsgoingtooslow【发布时间】:2018-07-3010:47:29【问题描述】:我正在尝试使用带有Fetching的聚集索引复制其他表中的6000万条记录。但是在2000万张唱片之后,它变得太慢了。我... 查看详情

导航到包含 ScrollView 的 ViewController 太慢了

】导航到包含ScrollView的ViewController太慢了【英文标题】:NavigatingtoViewControllercontainingScrollViewGoingtooSlow【发布时间】:2016-01-1807:55:50【问题描述】:这就是从ViewControllerA推送到ViewControllerB的方式UIStoryboard*mainStory=[UIStoryboardstoryboardW... 查看详情

呈现视图控制器太慢了

】呈现视图控制器太慢了【英文标题】:PresentingViewControlleristooslow【发布时间】:2020-05-2000:08:29【问题描述】:我已经在我的Swift应用中实现了FirebaseGoogle登录。我想在开始时检查它是否已经是登录用户。我是这样做的:overridefun... 查看详情

MySQL查询太慢了

】MySQL查询太慢了【英文标题】:MySQLquerytoomuchslow【发布时间】:2019-05-1423:21:59【问题描述】:我正在尝试查询以获取一些趋势统计数据,但基准测试真的很慢。查询执行时间约为134秒。我有一个名为table_1的MySQL表。在create语句... 查看详情

UIAlertController 在 iOS 9.3 中太慢了

】UIAlertController在iOS9.3中太慢了【英文标题】:UIAlertControlleristooslowiniOS9.3【发布时间】:2016-10-3123:35:19【问题描述】:在iOS9.3中执行任何按钮操作时,UIAlertController太慢。不确定是iOS9.3的问题还是缺少正确配置的内容。UIAlertContro... 查看详情

setFormulaArray 太慢了

】setFormulaArray太慢了【英文标题】:setFormulaArraytooslow【发布时间】:2021-06-0807:02:33【问题描述】:我正在尝试编写一个python包装器,该包装器旨在从csv(或mysql)读取多个记录并更新工作表预定义范围的值,该范围由值单元格和... 查看详情

Vscode typescript 样式的组件太慢了

】Vscodetypescript样式的组件太慢了【英文标题】:Vscodetypescriptstyledcomponenttooslow【发布时间】:2020-10-1008:32:58【问题描述】:当我使用styledcomponent时,我的vscode类型检查太慢了我已经多次搜索过这个问题,但我在hit-hub上发现了一... 查看详情

谷歌云部署太慢了

】谷歌云部署太慢了【英文标题】:GoogleClouddeploysoslow【发布时间】:2017-03-0504:06:30【问题描述】:我正在使用GoogleCloudNodeJS托管。当我将应用程序部署到GoogleCloud时,我感到非常惊讶。每次部署都非常慢。第一次可能会很慢,但... 查看详情

Rails Assets 预编译太慢了~12hrs

】RailsAssets预编译太慢了~12hrs【英文标题】:RailsAssetsprecompileistooslow~12hrs【发布时间】:2014-02-2406:28:11【问题描述】:我是本地预编译资产likethisRAILS_ENV=productionbundleexecrakeassets:precompile,但是12小时太慢了。我不知道会发生什么!... 查看详情

函数 scipy.interpolate.interpn() 太慢了

】函数scipy.interpolate.interpn()太慢了【英文标题】:Functionscipy.interpolate.interpn()muchtooslow【发布时间】:2022-01-1117:37:45【问题描述】:我正在使用scipy.interpolate.interpn()在二维网格上的单个点插入一个值。问题在于,对于这个单点和2D... 查看详情

Swift:tableView.reloadData() 太慢了

】Swift:tableView.reloadData()太慢了【英文标题】:Swift:tableView.reloadData()waytooslow【发布时间】:2015-08-2317:06:01【问题描述】:我正在尝试在我调用以填充我的UITableView的异步请求之后执行tableView.reloadData()调用。该表会在15-20秒后显... 查看详情

javacv视频压缩太慢了

参考技术A可直接按默认设置即可。所有参数都调整好之后,点击开始压缩视频就可以了。视频压缩通常指的是通过特定的压缩技术,比如调节视频的参数等,从而达到缩减视频大小节省空间的目的。 查看详情