-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix type cache cross pollination (#306)
* Add cross pollination specs and improve type filtering performance by caching * Add type rejection benchmark * Remove type checking during serialization, impossible to do * Remove bad type caching * Clean up code * Add type checking into serialization with a separate type caching
- Loading branch information
Showing
7 changed files
with
176 additions
and
27 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
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,46 @@ | ||
using System; | ||
using System.IO; | ||
using BenchmarkDotNet.Attributes; | ||
using Hyperion.Internal; | ||
|
||
namespace Hyperion.Benchmarks | ||
{ | ||
[Config(typeof(HyperionConfig))] | ||
public class TypeRejectionBenchmark | ||
{ | ||
private Serializer _serializer; | ||
private Stream _dangerousStream; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
var di = new DirectoryInfo("C:\\Windows\\Windows32"); | ||
var serializer = new Serializer(SerializerOptions.Default.WithDisallowUnsafeType(false)); | ||
_dangerousStream = new MemoryStream(); | ||
serializer.Serialize(di, _dangerousStream); | ||
|
||
_serializer = new Serializer(); | ||
} | ||
|
||
[GlobalCleanup] | ||
public void Cleanup() | ||
{ | ||
_dangerousStream.Dispose(); | ||
} | ||
|
||
[Benchmark] | ||
public void DeserializeDanger() | ||
{ | ||
_dangerousStream.Position = 0; | ||
try | ||
{ | ||
_serializer.Deserialize<DirectoryInfo>(_dangerousStream); | ||
} | ||
catch(EvilDeserializationException) | ||
{ | ||
// no-op | ||
} | ||
} | ||
|
||
} | ||
} |
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
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