             }
 
             // object is NSNumber and is not NaN or infinity
+            // For better performance, this (most expensive) test should be last.
             if let number = _SwiftValue.store(obj) as? NSNumber {
                 let invalid = number.doubleValue.isInfinite || number.doubleValue.isNaN
                 return !invalid

    
    mutating func serializeJSON(_ obj: Any) throws {

        switch (obj) {
        case let str as String:
            try serializeString(str)


            // object is a Double and is not NaN or infinity
            if let number = obj as? Double  {
                return number.isFinite
            }
            // object is a Float and is not NaN or infinity
            if let number = obj as? Float  {
                return number.isFinite
            }

            // object is Swift.Array
