Skip to content

Reduce CPU usage for Deserializer - #70

Open
agnosticdev wants to merge 2 commits into
mainfrom
agnosticdev/DeserializerPerformance
Open

Reduce CPU usage for Deserializer#70
agnosticdev wants to merge 2 commits into
mainfrom
agnosticdev/DeserializerPerformance

Conversation

@agnosticdev

Copy link
Copy Markdown
Collaborator

Change to help optimize generic operations on the Deserializer both internally and across module boundaries.
Running our Deserializer benchmark that creates 1 frame and runs the Deserializer on it 10,000,000 times I see this change cut the CPU usage in half.

Currently, top of tree:

434.41 M 89.1%	52.65 M	      specialized static Deserializer<>.deserialize<>(_:claim:_:)	
298.24 M 61.1%	13.00 M	       static Deserializer<>.deserialize<>(_:_:)	
262.99 M 53.9%	12.00 M	        specialized static Deserializer<>.deserialize<>(_:_:)	
191.63 M 39.3%	13.50 M	         partial apply for closure #1 in runtest()	
178.12 M 36.5%	25.97 M	          closure #1 in runtest()	
74.63 M  15.3%	27.44 M	           Deserializer<>.uint8(_:)	
27.00 M  5.5%	-      	           Deserializer<>.uint64NetworkByteOrder(_:)	
23.67 M  4.9%	-      	           Deserializer<>.uint16NetworkByteOrder(_:)	
14.54 M  3.0%	-      	           Deserializer<>.uint32NetworkByteOrder(_:)	
12.32 M  2.5%	12.32 M	           type metadata accessor for Deserializer<EmptySpanFactory>	
19.36 M  4.0%	19.36 M	         Deserializer<>.uint64NetworkByteOrder(_:)	
15.00 M  3.1%	15.00 M	         specialized Deserializer<>.finalResult.getter	
9.00 M   1.8%	9.00 M 	         Deserializer<>.init<>(_:)	
9.00 M   1.8%	9.00 M 	         Deserializer<>.uint32NetworkByteOrder(_:)	
7.00 M   1.4%	7.00 M 	         Deserializer<>.uint16NetworkByteOrder(_:)	
22.24 M  4.6%	22.24 M	        partial apply for closure #1 in runtest()	
83.53 M  17.1%	72.53 M	       Frame.bytes.getter	
11.00 M  2.3%	11.00 M	        Frame.startOffset.getter	

And with these changes:

217.45 M 87.5%	3.74 M 	      static Deserializer<>.deserialize<>(_:claim:_:)	
136.51 M 54.9%	21.00 M	       specialized static Deserializer<>.deserialize<>(_:_:)	
98.91 M  39.8%	3.42 M 	        partial apply for closure #1 in runtest()	
95.49 M  38.4%	-      	         closure #1 in runtest()	
42.62 M  17.1%	42.62 M	          specialized Deserializer<>.uint8(_:)	
19.24 M  7.7%	19.24 M	          specialized Deserializer<>.uint32NetworkByteOrder(_:)	
17.81 M  7.2%	17.81 M	          specialized Deserializer<>.uint16NetworkByteOrder(_:)	
15.81 M  6.4%	15.81 M	          specialized Deserializer<>.uint64NetworkByteOrder(_:)	
9.60 M   3.9%	9.60 M 	        Deserializer<>.init<>(_:)	
7.00 M   2.8%	7.00 M 	        specialized Deserializer<>.finalResult.getter	
57.63 M  23.2%	49.63 M	       Frame.bytes.getter	
19.57 M  7.9%	19.57 M	       partial apply for closure #1 in runtest()	
4.00 M   1.6%	-      	      specialized IndexingIterator.next()	

So as you can see these changes really help the generic functions optimize better.

Comment thread Sources/SwiftNetwork/Utilities/Deserializer.swift Outdated
@agnosticdev
agnosticdev requested review from kkuk24, rnro and rpaulo August 7, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants