-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,353 additions
and
402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Isolate parsing performance | ||
|
||
Parsing JSON on an isolate allows you to perform the operation in the background without blocking the main thread, which can be useful for large JSON files or when you need to perform other operations while parsing. | ||
|
||
**Parse on main thread took 20-60 microseconds.** | ||
|
||
**Parse using IsolateManager took 2400-2500 microseconds.** | ||
|
||
**Parse using Isolate.run took 110000-130000 microseconds.** | ||
|
||
```dart | ||
Future<T> executeInIsolate<T>({ | ||
required T Function(Response) mapper, | ||
required Response response, | ||
}) { | ||
return Isolate.run(() => mapper.call(response)); | ||
} | ||
``` | ||
|
||
These results were obtained : | ||
|
||
```dart | ||
final performRequest = (tokenPair) async { | ||
final response = await _createRequest(params, tokenPair); | ||
final timer = Stopwatch()..start(); | ||
params.responseMapper.call(response); | ||
log('Sync mapper: ${timer.elapsedMicroseconds}'); | ||
timer.stop(); | ||
final timer2 = Stopwatch()..start(); | ||
final result = await isolateManager.send(response, params.responseMapper); | ||
log('isolateManager.send: ${timer2.elapsedMicroseconds}'); | ||
timer2.stop(); | ||
final timer3 = Stopwatch()..start(); | ||
await executeInIsolate(mapper: params.responseMapper, response: response); | ||
log('execute in Isolate.run: ${timer3.elapsedMicroseconds}'); | ||
timer3.stop(); | ||
return result; | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.