Primary keys

Primary key support added through @PrimaryKey annotation.
Primary keys are only allowed on String, short, int, long.
Only 1 field can be a primary key. 
Primary key is automatically indexed if possible.

Some performance numbers (each test was run 10 times):

Label | Result | All results
------------ | -------------| -------------
Insert(10K) - nopk | mean: 0.193 s. - avg: 0.200 s. | [275, 194, 202, 192, 187, 199, 188, 189, 198, 184]
Insert(10K) - pk,string | mean: 1.526 s. - avg: 1.540 s. | [1654, 1559, 1559, 1530, 1514, 1522, 1512, 1495, 1541, 1522]
Insert(10K) - pk,long | mean: 0.303 s. - avg: 0.305 s. | [338, 310, 306, 304, 295, 301, 308, 297, 302, 290]
Insert(10K) - pk,string,index | mean: 0.939 s. - avg: 0.941 s. | [975, 904, 928, 926, 940, 939, 927, 968, 956, 950]
Insert(50K) - nopk | mean: 0.935 s. - avg: 0.938 s. | [1006, 946, 932, 934, 936, 911, 916, 939, 922, 945]
Insert(50K) - pk,string | mean: 19.657 s. - avg: 19.840 s. | [19684, 19582, 19671, 19587, 19636, 19644, 19614, 20202, 20041, 20744]
Insert(50K) - pk,long | mean: 3.593 s. - avg: 3.642 s. | [3838, 3714, 3529, 3567, 3522, 3491, 3562, 3620, 3761, 3819]
Insert(50K) - pk,string,index | mean: 4.891 s. - avg: 4.887 s. | [5189, 4638, 4812, 4892, 4905, 4891, 4672, 4854, 5005, 5012]





Currently no. This is due to how we handle new objects, by calling Realm.createObject(Class), which effectively creates a new object with default values, which include 0 or "" for primary keys. This also means you get an error when calling createObject() twice in a row.

This restriction is not ideal, and we should look for ways to remove it going forward, but for now it is necessary. .