Skip to content

Instantly share code, notes, and snippets.

View layomia's full-sized avatar

Layomi Akinrinade layomia

View GitHub Profile
@layomia
layomia / The Technical Interview Cheat Sheet.md
Created February 6, 2016 19:46 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@layomia
layomia / ImmutableDictPerf.md
Last active May 31, 2019 18:00
Immutable Dict Perf

Some performance notes.

TLDR

  • There's no significant performance impact on hot path (de)serialization i.e. primitives, objects, and enumerables.
  • There's a little (~4.6% avg.) regression for deserializing Dictionary, IDictionary, and IReadOnlyDictionary. This is due to some necessary if-checks introduced in shared code-paths between non-immutable dicts and immutable dicts. Splitting their code-paths entirely might mitigate this, but is beyond the scope for preview 6. This will be targeted in preview 7.
  • We might be able to improve the performance of (de)serializing ImmutableDicitonary, IImmutableDictionary, and ImmutableSortedDictionay by using IL emit to generate high performance CreateRange methods.

Hot-path deserialization and serialization use cases (Primitives, enumerables, objects)

These benchmarks live in the perf repo.

private static void HandleStartDictionary(JsonSerializerOptions options, ref ReadStack state)
{
Debug.Assert(!state.Current.IsProcessingEnumerable());
JsonPropertyInfo jsonPropertyInfo = state.Current.JsonPropertyInfo;
if (jsonPropertyInfo == null)
{
jsonPropertyInfo = state.Current.JsonClassInfo.CreateRootProperty(options);
}
private static void HandleStartObject(JsonSerializerOptions options, ref ReadStack state)
{
Debug.Assert(!state.Current.IsProcessingDictionary());
if (state.Current.IsProcessingEnumerable())
{
// A nested object within an enumerable.
Type objType = state.Current.GetElementType();
state.Push();
state.Current.Initialize(objType, options);

Converters

  • JsonDefaultArrayConverter<>
    • Single-dimentional arrays
  • JsonListOfTConverter<>
    • List
    • Types deriving from List
  • JsonDictionaryOfStringTValueConverter<,>
    • Dictionary<string, TValue>
  • Types deriving from Dictionary

Deserialize LoginViewModel

Method Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
Jil 492.3 ns 11.13 ns 11.43 ns 488.6 ns 479.8 ns 522.1 ns 0.0629 - - 264 B
JSON.NET 1,288.4 ns 26.17 ns 67.55 ns 1,263.9 ns 1,209.4 ns 1,493.6 ns 0.6618 - - 2776 B
Utf8Json 360.5 ns 3.07 ns 2.56 ns 360.4 ns 355.4 ns 365.5 ns 0.0668 - - 280 B
Default 517.7 ns 3.63 ns 3.03 ns 517.3 ns 512.5 ns 522.3 ns 0.0391 - - 168 B
AOT_LoadConverters 471.8 ns 9.14 ns 11.22 ns 469.3 ns 452.2 ns 494.5 ns 0.0401 - - 168 B
AOT_Raw 402.2 ns 10.17 ns 9.51 ns

Deserializing objects using parameterless constructors with JsonSerializer

Motivation

JsonSerializer deserializes instances of objects (classes and structs) using public parameterless constructors. If none is present, and deserialization is attempted, the serializer throws a NotSupportedException with a message stating that objects without public parameterless constructors, including interfaces and abstract types, are not supported for deserialization. There is no way to deserialize an instance of an object using a parameterized constructor.

sudo ./build.sh -subsetCategory coreclr -configuration Release
__DistroRid: linux-x64
__RuntimeId: linux-x64
Downloading 'https://dot.net/v1/dotnet-install.sh'
Trying to run 'curl https://dot.net/v1/dotnet-install.sh -sSL --retry 10 --create-dirs -o /home/layomia/repos/dotnet_runtime/.dotnet/dotnet-install.sh' for maximum of 5 attempts.
Ran 'curl https://dot.net/v1/dotnet-install.sh -sSL --retry 10 --create-dirs -o /home/layomia/repos/dotnet_runtime/.dotnet/dotnet-install.sh' successfully.
dotnet_install: Warning: Unable to locate zlib. Probable prerequisite missing; install zlib.
dotnet-install: Downloading link: https://dotnetcli.azureedge.net/dotnet/Sdk/5.0.100-preview.3.20168.11/dotnet-sdk-5.0.100-preview.3.20168.11-linux-x64.tar.gz
dotnet-install: Extracting zip from https://dotnetcli.azureedge.net/dotnet/Sdk/5.0.100-preview.3.20168.11/dotnet-sdk-5.0.100-preview.3.20168.11-linux-x64.tar.gz
dotnet-install: Adding to current process PATH: `/home/layomia/repos/dotnet_runtime/.dotnet`. Note: This change will
@layomia
layomia / JsonIgnore_API_change.md
Last active March 23, 2020 21:04
JsonIgnore_API_change

Approach A

/// <summary>
/// Prevents a property from being serialized or deserialized.
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public sealed class JsonIgnoreAttribute : JsonAttribute
{
    /// <summary>
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace RefHandlingDemo
{
class Program
{
static void Main(string[] args)