Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contract Examples and Metrics #1829

Closed
MaksymZavershynskyi opened this issue Dec 6, 2019 · 21 comments
Closed

Contract Examples and Metrics #1829

MaksymZavershynskyi opened this issue Dec 6, 2019 · 21 comments
Assignees
Labels
A-transaction-runtime Area: transaction runtime (transaction and receipts processing, state transition, etc) C-epic Category: an epic P-low Priority: low

Comments

@MaksymZavershynskyi
Copy link
Contributor

MaksymZavershynskyi commented Dec 6, 2019

We need to have examples of typical blockchain contracts and we need to study these contracts: how much gas use, how much TPS they allow, how many cross-contract hops do they take.

@MaksymZavershynskyi MaksymZavershynskyi added A-transaction-runtime Area: transaction runtime (transaction and receipts processing, state transition, etc) runtime-stability labels Dec 6, 2019
@MaksymZavershynskyi MaksymZavershynskyi self-assigned this Dec 6, 2019
@ilblackdragon ilblackdragon added this to the MainNet milestone Dec 8, 2019
@MaksymZavershynskyi MaksymZavershynskyi added P-low Priority: low and removed runtime-stability labels Jan 20, 2020
@MaksymZavershynskyi MaksymZavershynskyi changed the title Profile various standard contracts that we have in terms of gas usage Contract Examples and Metrics Jan 21, 2020
@MaksymZavershynskyi MaksymZavershynskyi added the C-epic Category: an epic label Jan 21, 2020
@MaksymZavershynskyi
Copy link
Contributor Author

For the record, as reported by @k06a when working with eth-bridge the cost of submitting Eth block header (70KiB -- 1200 hashes input) takes 0.1e15 gas which is a lot. The current gas limit of per transaction in 0.2e15. 99% of this gas is JSON parsing and 1% is actual math. JSON parsing is already optimized, it uses hex-encoding for hashes, and does other optimizations. CC @vgrichina

@k06a
Copy link
Contributor

k06a commented Jan 30, 2020

I'd suggest considering serializing to Borsh on the near node before passing arguments into a smart contract, to keep nearlib maintain JSON since it is more handle for end-user.

@k06a
Copy link
Contributor

k06a commented Jan 31, 2020

This is an example of gas consumption of near-bridge smart contract, 0.24e15 in total:

[ethbridge]: Deserializing first header, gas used: 192712610482203
[ethbridge]: First header deserialized, gas used:  193226777229851
[ethbridge]: Deserializing next header, gas used:  193252150782830
[ethbridge]: Deserialized header, gas used:        193760137312400
[ethbridge]: Validating header, gas used:          193771629916761
[ethbridge]: Header is valid, gas used:            240276575013584

@evgenykuzyakov
Copy link
Collaborator

Here is the full testing results, going to summarize them in the next comment:

Base gas cost of full noop call is 0
Base gas cost of calling a function with near_bindgen is 998,800,089
Extra cost of JSON input for an extra character in an argument name e.g. (aa: u32) vs (a: u32) 351,803,305
 -> INTEGERS <-
 -> JSON Inputs <-
Cost of JSON input of (a: u32) where a=1 is 14,101,273,583 difference for 1 digit is 14,101,273,583
Cost of JSON input of (a: u32) where a=10 is 14,549,486,163 difference for 1 digit is 448,212,580
Cost of JSON input of (a: u32) where a=100 is 14,997,698,743 difference for 1 digit is 448,212,580
Cost of JSON input of (a: u32) where a=1,000 is 15,445,911,323 difference for 1 digit is 448,212,580
Cost of JSON input of (a: u32) where a=10,000 is 15,894,123,903 difference for 1 digit is 448,212,580
Cost of JSON input of (a: u32) where a=100,000 is 16,342,336,483 difference for 1 digit is 448,212,580
Cost of JSON input of (a: u32) where a=1,000,000 is 16,790,549,063 difference for 1 digit is 448,212,580
Cost of JSON input of (a: u32) where a=10,000,000 is 17,238,761,643 difference for 1 digit is 448,212,580
Cost of JSON input of (a: u32) where a=100,000,000 is 17,686,974,223 difference for 1 digit is 448,212,580
Cost of JSON input of (a: u32) where a=1,000,000,000 is 18,135,186,803 difference for 1 digit is 448,212,580
Cost of JSON input of (a: u32, b: u32) where a=b=1 is 20,567,683,360 difference for 2 digit is 20,567,683,360
Cost of JSON input of (a: u32, b: u32) where a=b=10 is 21,464,108,520 difference for 2 digit is 896,425,160
Cost of JSON input of (a: u32, b: u32) where a=b=100 is 22,426,091,987 difference for 2 digit is 961,983,467
Cost of JSON input of (a: u32, b: u32) where a=b=1,000 is 23,256,958,840 difference for 2 digit is 830,866,853
Cost of JSON input of (a: u32, b: u32) where a=b=10,000 is 24,153,384,000 difference for 2 digit is 896,425,160
Cost of JSON input of (a: u32, b: u32) where a=b=100,000 is 25,049,809,160 difference for 2 digit is 896,425,160
Cost of JSON input of (a: u32, b: u32) where a=b=1,000,000 is 26,011,792,627 difference for 2 digit is 961,983,467
Cost of JSON input of (a: u32, b: u32) where a=b=10,000,000 is 26,842,659,480 difference for 2 digit is 830,866,853
Cost of JSON input of (a: u32, b: u32) where a=b=100,000,000 is 27,739,084,640 difference for 2 digit is 896,425,160
Cost of JSON input of (a: u32, b: u32) where a=b=1,000,000,000 is 28,635,509,800 difference for 2 digit is 896,425,160
 -> JSON Outputs <-
Cost of JSON output of u32=1 is 5,650,652,325 difference for 1 digit is 5,650,652,325
Cost of JSON output of u32=10 is 5,731,759,932 difference for 1 digit is 81,107,607
Cost of JSON output of u32=100 is 5,874,569,475 difference for 1 digit is 142,809,543
Cost of JSON output of u32=1,000 is 5,955,677,082 difference for 1 digit is 81,107,607
Cost of JSON output of u32=10,000 is 6,117,768,480 difference for 1 digit is 162,091,398
Cost of JSON output of u32=100,000 is 6,198,876,087 difference for 1 digit is 81,107,607
Cost of JSON output of u32=1,000,000 is 6,341,685,630 difference for 1 digit is 142,809,543
Cost of JSON output of u32=10,000,000 is 6,422,793,237 difference for 1 digit is 81,107,607
Cost of JSON output of u32=100,000,000 is 6,584,884,635 difference for 1 digit is 162,091,398
Cost of JSON output of u32=1,000,000,000 is 6,665,992,242 difference for 1 digit is 81,107,607
 -> Borsh Input/Output <-
Cost of Borsh input of (a: u32) is 7,850,458,387
Cost of Borsh input of (a: u32, b: u32) is 9,716,579,756
Cost of Borsh output of u32 is 5,546,901,756
 -> STRINGS <-
 -> JSON Inputs <-
Cost of JSON input of (s: String) where s="" is 15,367,036,815 difference for 1 char is 15,367,036,815
Cost of JSON input of (s: String) where s="h" is 17,022,293,518 difference for 1 char is 1,655,256,703
Cost of JSON input of (s: String) where s="he" is 17,416,516,904 difference for 1 char is 394,223,386
Cost of JSON input of (s: String) where s="hel" is 17,675,767,305 difference for 1 char is 259,250,401
Cost of JSON input of (s: String) where s="hell" is 17,935,017,706 difference for 1 char is 259,250,401
Cost of JSON input of (s: String) where s="hello" is 18,194,268,107 difference for 1 char is 259,250,401
Cost of JSON input of (s: String) where s="hello " is 18,453,518,508 difference for 1 char is 259,250,401
Cost of JSON input of (s: String) where s="hello w" is 18,712,768,909 difference for 1 char is 259,250,401
Cost of JSON input of (s: String) where s="hello wo" is 18,972,019,310 difference for 1 char is 259,250,401
Cost of JSON input of (s: String) where s="hello wor" is 18,888,052,692 difference for 1 char is -83,966,618
Cost of JSON input of (s: String) where s="hello worl" is 19,139,590,351 difference for 1 char is 251,537,659
Cost of JSON input of (s: String) where s="hello world" is 19,398,840,752 difference for 1 char is 259,250,401
 -> JSON Outputs <-
Cost of JSON output of String where s="" is 6,715,134,537 difference for 1 char is 6,715,134,537
Cost of JSON output of String where s="h" is 7,644,643,764 difference for 1 char is 929,509,227
Cost of JSON output of String where s="he" is 7,795,166,049 difference for 1 char is 150,522,285
Cost of JSON output of String where s="hel" is 7,945,688,334 difference for 1 char is 150,522,285
Cost of JSON output of String where s="hell" is 8,096,210,619 difference for 1 char is 150,522,285
Cost of JSON output of String where s="hello" is 8,246,732,904 difference for 1 char is 150,522,285
Cost of JSON output of String where s="hello " is 8,397,255,189 difference for 1 char is 150,522,285
Cost of JSON output of String where s="hello w" is 8,547,777,474 difference for 1 char is 150,522,285
Cost of JSON output of String where s="hello wo" is 8,698,299,759 difference for 1 char is 150,522,285
Cost of JSON output of String where s="hello wor" is 8,848,822,044 difference for 1 char is 150,522,285
Cost of JSON output of String where s="hello worl" is 8,999,344,329 difference for 1 char is 150,522,285
Cost of JSON output of String where s="hello world" is 9,149,866,614 difference for 1 char is 150,522,285
 -> Borsh Input <-
Cost of Borsh input of (s: String) where s="" is 10,457,365,183 difference for 1 char is 10,457,365,183
Cost of Borsh input of (s: String) where s="h" is 12,139,616,483 difference for 1 char is 1,682,251,300
Cost of Borsh input of (s: String) where s="he" is 13,605,911,007 difference for 1 char is 1,466,294,524
Cost of Borsh input of (s: String) where s="hel" is 15,072,205,531 difference for 1 char is 1,466,294,524
Cost of Borsh input of (s: String) where s="hell" is 16,538,500,055 difference for 1 char is 1,466,294,524
Cost of Borsh input of (s: String) where s="hello" is 18,004,794,579 difference for 1 char is 1,466,294,524
Cost of Borsh input of (s: String) where s="hello " is 19,471,089,103 difference for 1 char is 1,466,294,524
Cost of Borsh input of (s: String) where s="hello w" is 20,937,383,627 difference for 1 char is 1,466,294,524
Cost of Borsh input of (s: String) where s="hello wo" is 22,060,461,132 difference for 1 char is 1,123,077,505
Cost of Borsh input of (s: String) where s="hello wor" is 23,519,042,914 difference for 1 char is 1,458,581,782
Cost of Borsh input of (s: String) where s="hello worl" is 24,985,337,438 difference for 1 char is 1,466,294,524
Cost of Borsh input of (s: String) where s="hello world" is 26,451,631,962 difference for 1 char is 1,466,294,524
 -> Borsh Outputs <-
Cost of Borsh output of String where s="" is 6,187,059,342 difference for 1 char is 6,187,059,342
Cost of Borsh output of String where s="h" is 6,264,310,578 difference for 1 char is 77,251,236
Cost of Borsh output of String where s="he" is 6,329,992,701 difference for 1 char is 65,682,123
Cost of Borsh output of String where s="hel" is 6,395,674,824 difference for 1 char is 65,682,123
Cost of Borsh output of String where s="hell" is 6,461,356,947 difference for 1 char is 65,682,123
Cost of Borsh output of String where s="hello" is 6,527,039,070 difference for 1 char is 65,682,123
Cost of Borsh output of String where s="hello " is 6,592,721,193 difference for 1 char is 65,682,123
Cost of Borsh output of String where s="hello w" is 6,658,403,316 difference for 1 char is 65,682,123
Cost of Borsh output of String where s="hello wo" is 6,724,085,439 difference for 1 char is 65,682,123
Cost of Borsh output of String where s="hello wor" is 6,789,767,562 difference for 1 char is 65,682,123
Cost of Borsh output of String where s="hello worl" is 6,855,449,685 difference for 1 char is 65,682,123
Cost of Borsh output of String where s="hello world" is 6,921,131,808 difference for 1 char is 65,682,123
 -> Vec<u8> <-
 -> JSON Inputs <-
Cost of JSON input of (v: Vec<u8>) where v=[] is 14,996,825,199 difference for 1 element is 14,996,825,199
Cost of JSON input of (v: Vec<u8>) where v=[1] is 19,201,143,133 difference for 1 element is 4,204,317,934
Cost of JSON input of (v: Vec<u8>) where v=[1, 2] is 24,382,870,018 difference for 1 element is 5,181,726,885
Cost of JSON input of (v: Vec<u8>) where v=[1, 2, 3] is 29,240,661,739 difference for 1 element is 4,857,791,721
Cost of JSON input of (v: Vec<u8>) where v=[1, 2, 3, 4] is 32,617,606,996 difference for 1 element is 3,376,945,257
Cost of JSON input of (v: Vec<u8>) where v=[1, 2, 3, 4, 5] is 37,996,008,802 difference for 1 element is 5,378,401,806
Cost of JSON input of (v: Vec<u8>) where v=[1, 2, 3, 4, 5, 6] is 41,372,954,059 difference for 1 element is 3,376,945,257
Cost of JSON input of (v: Vec<u8>) where v=[1, 2, 3, 4, 5, 6, 7] is 44,749,899,316 difference for 1 element is 3,376,945,257
Cost of JSON input of (v: Vec<u8>) where v=[1, 2, 3, 4, 5, 6, 7, 8] is 48,126,844,573 difference for 1 element is 3,376,945,257
Cost of JSON input of (v: Vec<u8>) where v=[1, 2, 3, 4, 5, 6, 7, 8, 9] is 53,732,772,268 difference for 1 element is 5,605,927,695
Cost of JSON input of (v: Vec<u8>) where v=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is 57,557,930,105 difference for 1 element is 3,825,157,837
 -> JSON Outputs <-
Cost of JSON output of Vec<u8> where v=[] is 6,799,974,699 difference for 1 element is 6,799,974,699
Cost of JSON output of Vec<u8> where v=[1] is 8,292,514,092 difference for 1 element is 1,492,539,393
Cost of JSON output of Vec<u8> where v=[1, 2] is 10,282,649,160 difference for 1 element is 1,990,135,068
Cost of JSON output of Vec<u8> where v=[1, 2, 3] is 12,272,784,228 difference for 1 element is 1,990,135,068
Cost of JSON output of Vec<u8> where v=[1, 2, 3, 4] is 14,262,919,296 difference for 1 element is 1,990,135,068
Cost of JSON output of Vec<u8> where v=[1, 2, 3, 4, 5] is 16,253,054,364 difference for 1 element is 1,990,135,068
Cost of JSON output of Vec<u8> where v=[1, 2, 3, 4, 5, 6] is 18,243,189,432 difference for 1 element is 1,990,135,068
Cost of JSON output of Vec<u8> where v=[1, 2, 3, 4, 5, 6, 7] is 20,233,324,500 difference for 1 element is 1,990,135,068
Cost of JSON output of Vec<u8> where v=[1, 2, 3, 4, 5, 6, 7, 8] is 22,223,459,568 difference for 1 element is 1,990,135,068
Cost of JSON output of Vec<u8> where v=[1, 2, 3, 4, 5, 6, 7, 8, 9] is 24,094,047,135 difference for 1 element is 1,870,587,567
Cost of JSON output of Vec<u8> where v=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is 26,165,289,810 difference for 1 element is 2,071,242,675
 -> Borsh Input <-
Cost of Borsh input of (v: Vec<u8>) where v=[] is 9,963,749,695 difference for 1 element is 9,963,749,695
Cost of Borsh input of (v: Vec<u8>) where v=[1] is 11,337,491,315 difference for 1 element is 1,373,741,620
Cost of Borsh input of (v: Vec<u8>) where v=[1, 2] is 12,711,232,935 difference for 1 element is 1,373,741,620
Cost of Borsh input of (v: Vec<u8>) where v=[1, 2, 3] is 14,084,974,555 difference for 1 element is 1,373,741,620
Cost of Borsh input of (v: Vec<u8>) where v=[1, 2, 3, 4] is 15,458,716,175 difference for 1 element is 1,373,741,620
Cost of Borsh input of (v: Vec<u8>) where v=[1, 2, 3, 4, 5] is 16,832,457,795 difference for 1 element is 1,373,741,620
Cost of Borsh input of (v: Vec<u8>) where v=[1, 2, 3, 4, 5, 6] is 18,206,199,415 difference for 1 element is 1,373,741,620
Cost of Borsh input of (v: Vec<u8>) where v=[1, 2, 3, 4, 5, 6, 7] is 19,579,941,035 difference for 1 element is 1,373,741,620
Cost of Borsh input of (v: Vec<u8>) where v=[1, 2, 3, 4, 5, 6, 7, 8] is 20,953,682,655 difference for 1 element is 1,373,741,620
Cost of Borsh input of (v: Vec<u8>) where v=[1, 2, 3, 4, 5, 6, 7, 8, 9] is 22,327,424,275 difference for 1 element is 1,373,741,620
Cost of Borsh input of (v: Vec<u8>) where v=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is 23,701,165,895 difference for 1 element is 1,373,741,620
 -> Borsh Outputs <-
Cost of Borsh output of Vec<u8> where v=[] is 5,755,145,790 difference for 1 element is 5,755,145,790
Cost of Borsh output of Vec<u8> where v=[1] is 6,433,990,902 difference for 1 element is 678,845,112
Cost of Borsh output of Vec<u8> where v=[1, 2] is 7,112,836,014 difference for 1 element is 678,845,112
Cost of Borsh output of Vec<u8> where v=[1, 2, 3] is 7,791,681,126 difference for 1 element is 678,845,112
Cost of Borsh output of Vec<u8> where v=[1, 2, 3, 4] is 8,470,526,238 difference for 1 element is 678,845,112
Cost of Borsh output of Vec<u8> where v=[1, 2, 3, 4, 5] is 9,149,371,350 difference for 1 element is 678,845,112
Cost of Borsh output of Vec<u8> where v=[1, 2, 3, 4, 5, 6] is 9,828,216,462 difference for 1 element is 678,845,112
Cost of Borsh output of Vec<u8> where v=[1, 2, 3, 4, 5, 6, 7] is 10,507,061,574 difference for 1 element is 678,845,112
Cost of Borsh output of Vec<u8> where v=[1, 2, 3, 4, 5, 6, 7, 8] is 11,185,906,686 difference for 1 element is 678,845,112
Cost of Borsh output of Vec<u8> where v=[1, 2, 3, 4, 5, 6, 7, 8, 9] is 11,864,751,798 difference for 1 element is 678,845,112
Cost of Borsh output of Vec<u8> where v=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is 12,543,596,910 difference for 1 element is 678,845,112
 -> Vec<u32> <-
 -> JSON Inputs <-
Cost of JSON input of (v: Vec<u32>) where v=[] is 14,792,437,536 difference for 1 element is 14,792,437,536
Cost of JSON input of (v: Vec<u32>) where v=[1] is 19,251,275,956 difference for 1 element is 4,458,838,420
Cost of JSON input of (v: Vec<u32>) where v=[1, 2] is 24,884,198,248 difference for 1 element is 5,632,922,292
Cost of JSON input of (v: Vec<u32>) where v=[1, 2, 3] is 30,744,646,429 difference for 1 element is 5,860,448,181
Cost of JSON input of (v: Vec<u32>) where v=[1, 2, 3, 4] is 34,144,729,912 difference for 1 element is 3,400,083,483
Cost of JSON input of (v: Vec<u32>) where v=[1, 2, 3, 4, 5] is 40,410,097,048 difference for 1 element is 6,265,367,136
Cost of JSON input of (v: Vec<u32>) where v=[1, 2, 3, 4, 5, 6] is 43,810,180,531 difference for 1 element is 3,400,083,483
Cost of JSON input of (v: Vec<u32>) where v=[1, 2, 3, 4, 5, 6, 7] is 47,210,264,014 difference for 1 element is 3,400,083,483
Cost of JSON input of (v: Vec<u32>) where v=[1, 2, 3, 4, 5, 6, 7, 8] is 50,610,347,497 difference for 1 element is 3,400,083,483
Cost of JSON input of (v: Vec<u32>) where v=[1, 2, 3, 4, 5, 6, 7, 8, 9] is 57,924,647,545 difference for 1 element is 7,314,300,048
Cost of JSON input of (v: Vec<u32>) where v=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is 61,772,943,608 difference for 1 element is 3,848,296,063
 -> JSON Outputs <-
Cost of JSON output of Vec<u32> where v=[] is 6,584,017,923 difference for 1 element is 6,584,017,923
Cost of JSON output of Vec<u32> where v=[1] is 8,188,392,075 difference for 1 element is 1,604,374,152
Cost of JSON output of Vec<u32> where v=[1, 2] is 10,290,361,902 difference for 1 element is 2,101,969,827
Cost of JSON output of Vec<u32> where v=[1, 2, 3] is 12,272,784,228 difference for 1 element is 1,982,422,326
Cost of JSON output of Vec<u32> where v=[1, 2, 3, 4] is 14,374,754,055 difference for 1 element is 2,101,969,827
Cost of JSON output of Vec<u32> where v=[1, 2, 3, 4, 5] is 16,476,723,882 difference for 1 element is 2,101,969,827
Cost of JSON output of Vec<u32> where v=[1, 2, 3, 4, 5, 6] is 18,578,693,709 difference for 1 element is 2,101,969,827
Cost of JSON output of Vec<u32> where v=[1, 2, 3, 4, 5, 6, 7] is 20,680,663,536 difference for 1 element is 2,101,969,827
Cost of JSON output of Vec<u32> where v=[1, 2, 3, 4, 5, 6, 7, 8] is 22,782,633,363 difference for 1 element is 2,101,969,827
Cost of JSON output of Vec<u32> where v=[1, 2, 3, 4, 5, 6, 7, 8, 9] is 24,884,603,190 difference for 1 element is 2,101,969,827
Cost of JSON output of Vec<u32> where v=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is 27,067,680,624 difference for 1 element is 2,183,077,434
 -> Borsh Input <-
Cost of Borsh input of (v: Vec<u32>) where v=[] is 9,736,223,806 difference for 1 element is 9,736,223,806
Cost of Borsh input of (v: Vec<u32>) where v=[1] is 11,640,908,885 difference for 1 element is 1,904,685,079
Cost of Borsh input of (v: Vec<u32>) where v=[1, 2] is 13,545,593,964 difference for 1 element is 1,904,685,079
Cost of Borsh input of (v: Vec<u32>) where v=[1, 2, 3] is 15,450,279,043 difference for 1 element is 1,904,685,079
Cost of Borsh input of (v: Vec<u32>) where v=[1, 2, 3, 4] is 17,354,964,122 difference for 1 element is 1,904,685,079
Cost of Borsh input of (v: Vec<u32>) where v=[1, 2, 3, 4, 5] is 19,259,649,201 difference for 1 element is 1,904,685,079
Cost of Borsh input of (v: Vec<u32>) where v=[1, 2, 3, 4, 5, 6] is 21,164,334,280 difference for 1 element is 1,904,685,079
Cost of Borsh input of (v: Vec<u32>) where v=[1, 2, 3, 4, 5, 6, 7] is 23,069,019,359 difference for 1 element is 1,904,685,079
Cost of Borsh input of (v: Vec<u32>) where v=[1, 2, 3, 4, 5, 6, 7, 8] is 24,973,704,438 difference for 1 element is 1,904,685,079
Cost of Borsh input of (v: Vec<u32>) where v=[1, 2, 3, 4, 5, 6, 7, 8, 9] is 26,878,389,517 difference for 1 element is 1,904,685,079
Cost of Borsh input of (v: Vec<u32>) where v=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is 28,783,074,596 difference for 1 element is 1,904,685,079
 -> Borsh Outputs <-
Cost of Borsh output of Vec<u32> where v=[] is 5,635,598,289 difference for 1 element is 5,635,598,289
Cost of Borsh output of Vec<u32> where v=[1] is 6,654,175,497 difference for 1 element is 1,018,577,208
Cost of Borsh output of Vec<u32> where v=[1, 2] is 7,672,752,705 difference for 1 element is 1,018,577,208
Cost of Borsh output of Vec<u32> where v=[1, 2, 3] is 8,691,329,913 difference for 1 element is 1,018,577,208
Cost of Borsh output of Vec<u32> where v=[1, 2, 3, 4] is 9,709,907,121 difference for 1 element is 1,018,577,208
Cost of Borsh output of Vec<u32> where v=[1, 2, 3, 4, 5] is 10,728,484,329 difference for 1 element is 1,018,577,208
Cost of Borsh output of Vec<u32> where v=[1, 2, 3, 4, 5, 6] is 11,747,061,537 difference for 1 element is 1,018,577,208
Cost of Borsh output of Vec<u32> where v=[1, 2, 3, 4, 5, 6, 7] is 12,765,638,745 difference for 1 element is 1,018,577,208
Cost of Borsh output of Vec<u32> where v=[1, 2, 3, 4, 5, 6, 7, 8] is 13,784,215,953 difference for 1 element is 1,018,577,208
Cost of Borsh output of Vec<u32> where v=[1, 2, 3, 4, 5, 6, 7, 8, 9] is 14,802,793,161 difference for 1 element is 1,018,577,208
Cost of Borsh output of Vec<u32> where v=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is 15,821,370,369 difference for 1 element is 1,018,577,208
 -> SIMPLE STRUCT <-
Extra cost of JSON input of {"a": {"a": 1}} vs {"a": 1} 5,408,890,579
Extra cost of JSON output of {"a": {"a": 1}} vs {"a": 1} 5,904,846,897
Extra cost of Borsh input of {"a": {"a": 1}} vs {"a": 1} 115,691,130
Extra cost of Borsh output of {"a": {"a": 1}} vs {"a": 1} 158,111,211

@evgenykuzyakov
Copy link
Collaborator

evgenykuzyakov commented Feb 29, 2020

Base gas cost of full noop call is 0
Base gas cost of calling a function with near_bindgen is 998,800,089

Extra cost of JSON input for an extra character in an argument name e.g. (aa: u32) vs (a: u32) 351,803,305

Integers

Cost of JSON input of (a: u32) where a=1 is 14,101,273,583
Extra cost of JSON for an additional digit in the input is 448,212,580
Cost of JSON input of (a: u32, b: u32) where a=1 and b=1 is 20,567,683,360
Extra cost of JSON for 2 additional digits in the input is 896,425,160
Cost of JSON output of u32=1 is 5,650,652,325
Extra cost of JSON for an additional digit in the output is 116,779,039

Cost of Borsh input of (a: u32) is 7,850,458,387
Cost of Borsh input of (a: u32, b: u32) is 9,716,579,756
Cost of Borsh output of u32 is 5,546,901,756
There are no extra cost for additional digits

String

Cost of JSON input of (s: String) where s="" is 15,367,036,815
Cost of JSON input of (s: String) where s="h" is 17,022,293,518 (+1,655,256,703)
Average extra cost of JSON for an additional char in the input is 237,654,723

Cost of JSON output of String where s="" is 6,715,134,537
Cost of JSON output of String where s="h" is 7,644,643,764 (+929,509,227)
Average extra cost of JSON for an additional char in the output is 150,522,285

Cost of Borsh input of (s: String) where s="" is 10,457,365,183
Cost of Borsh input of (s: String) where s="h" is 12,139,616,483 (+1,682,251,300)
Average extra cost of Borsh for an additional char in the input is 1,431,201,548

Cost of Borsh output of String where s="" is 6,187,059,342
Cost of Borsh output of String where s="h" is 6,264,310,578 (+77,251,236)
Average extra cost of Borsh for an additional char in the output is 65,682,123

Vec<u8>

Cost of JSON input of (v: Vec) where v=[] is 14,996,825,199
Cost of JSON input of (v: Vec) where v=[1] is 19,201,143,133 (+4,204,317,934)
Average extra cost of JSON for an additional number in the input is 4,261,865,219

Cost of JSON output of Vec where v=[] is 6,799,974,699
Cost of JSON output of Vec where v=[1] is 8,292,514,092 (+1,492,539,393)
Average extra cost of JSON for an additional number in the output is 1,985,863,969

Cost of Borsh input of (v: Vec) where v=[] is 9,963,749,695
Cost of Borsh input of (v: Vec) where v=[1] is 11,337,491,315 (+1,373,741,620)
Average extra cost of Borsh for an additional number in the input is 1,373,741,620

Cost of Borsh output of Vec where v=[] is 5,755,145,790
Cost of Borsh output of Vec where v=[1] is 6,433,990,902 (+678,845,112)
Average extra cost of Borsh for an additional number in the output is 678,845,112

Vec<u32>

Cost of JSON input of (v: Vec) where v=[] is 14,792,437,536
Cost of JSON input of (v: Vec) where v=[1] is 19,251,275,956 (+4,458,838,420)
Average extra cost of JSON for an additional number in the input is 4,724,629,739

Cost of JSON output of Vec where v=[] is 6,584,017,923
Cost of JSON output of Vec where v=[1] is 8,188,392,075 (+1,604,374,152)
Average extra cost of JSON for an additional number in the output is 2,097,698,728

Cost of Borsh input of (v: Vec) where v=[] is 9,736,223,806
Cost of Borsh input of (v: Vec) where v=[1] is 11,640,908,885 (+1,904,685,079)
Average extra cost of Borsh for an additional number in the input is 1,904,685,079

Cost of Borsh output of Vec where v=[] is 5,635,598,289
Cost of Borsh output of Vec where v=[1] is 6,654,175,497 (+1,018,577,208)
Average extra cost of Borsh for an additional number in the output is 1,018,577,208

SIMPLE STRUCT

pub struct A {
    a: u32,
}

Extra cost of JSON input of {"a": {"a": 1}} vs {"a": 1} 5,408,890,579
Extra cost of JSON output of {"a": {"a": 1}} vs {"a": 1} 5,904,846,897
Extra cost of Borsh input of {"a": {"a": 1}} vs {"a": 1} 115,691,130
Extra cost of Borsh output of {"a": {"a": 1}} vs {"a": 1} 158,111,211

@MaksymZavershynskyi
Copy link
Contributor Author

@vgrichina ^

@MaksymZavershynskyi
Copy link
Contributor Author

Extra cost of Borsh per string char argument is higher than with JSON.
I wonder whether this is because we are actually verifying that the string is a valid UTF8 here: https://github.com/nearprotocol/borsh/blob/master/borsh-rs/borsh/src/de/mod.rs#L159
@evgenykuzyakov Could you please check what would happen if we replace it with https://doc.rust-lang.org/std/string/struct.String.html#method.from_utf8_unchecked ?

@evgenykuzyakov
Copy link
Collaborator

Well it's not about the String, see Vec<u8>:

Vec<u8>
Cost of JSON input of (v: Vec) where v=[] is 14,996,825,199

Cost of Borsh input of (v: Vec) where v=[] is 9,963,749,695
Cost of Borsh input of (v: Vec) where v=[1] is 11,337,491,315 (+1,373,741,620)
Average extra cost of Borsh for an additional number in the input is 1,373,741,620

vs String:

Average extra cost of Borsh for an additional char in the input is 1,431,201,548

@MaksymZavershynskyi
Copy link
Contributor Author

It might be related to the fact that Borsh deserialization is slower than bincode http://borsh.io/ . Something about the way we are reading slices of bytes is very unoptimal.

@evgenykuzyakov
Copy link
Collaborator

Switched String deserialization with the following:

impl BorshDeserialize for String {
    #[inline]
    fn deserialize<R: Read>(reader: &mut R) -> Result<Self, Error> {
        let len = u32::deserialize(reader)?;
        // TODO(16): return capacity allocation when we have the size of the buffer left from the reader.
        let mut result = Vec::with_capacity(hint::cautious::<u8>(len));
        let mut i = 0;
        let batch_len = 1024;
        while i < len {
            let sz = std::cmp::min(i + batch_len, len) - i;
            let mut buf = vec![0u8; sz as usize];
            reader.read_exact(&mut buf)?;
            result.extend_from_slice(&buf);
            i += sz;
        }
        String::from_utf8(result)
            .map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err.to_string()))
    }
}

Got the following results for String:

 -> Borsh Input <-
Cost of Borsh input of (s: String) where s="" is 10,310,823,085 difference for 1 char is 10,310,823,085
Cost of Borsh input of (s: String) where s="h" is 14,337,747,953 difference for 1 char is 4,026,924,868
Average diff 262,721,135
 -> Borsh Outputs <-
Cost of Borsh output of String where s="" is 5,820,704,097 difference for 1 char is 5,820,704,097
Cost of Borsh output of String where s="h" is 5,897,955,333 difference for 1 char is 77,251,236
Average diff 65,682,123

@MaksymZavershynskyi
Copy link
Contributor Author

Very cool, we should do the same for Vec<u8> and then rerun benchmarks for Borsh, maybe we will catch up with bincode.

@evgenykuzyakov
Copy link
Collaborator

Latest:

 -> STRINGS <-

 -> Borsh Input <-
Cost of Borsh input of (s: String) where s="" is 8,463,621,376 difference for 1 char is 8,463,621,376
Cost of Borsh input of (s: String) where s="h" is 12,089,483,660 difference for 1 char is 3,625,862,284
Cost of Borsh input of (s: String) where s="he" is 12,495,276,159 difference for 1 char is 405,792,499
Cost of Borsh input of (s: String) where s="hel" is 12,708,250,108 difference for 1 char is 212,973,949
Average diff 197,162,828


 -> Vec<u8> <-

 -> Borsh Input <-
Cost of Borsh input of (v: Vec<u8>) where v=[] is 8,452,052,263 difference for 1 element is 8,452,052,263
Cost of Borsh input of (v: Vec<u8>) where v=[1] is 11,352,916,799 difference for 1 element is 2,900,864,536
Cost of Borsh input of (v: Vec<u8>) where v=[1, 2] is 11,704,720,104 difference for 1 element is 351,803,305
Cost of Borsh input of (v: Vec<u8>) where v=[1, 2, 3] is 11,863,704,859 difference for 1 element is 158,984,755
Average diff 180,409,038


 -> Vec<u32> <-

 -> Borsh Input <-
Cost of Borsh input of (v: Vec<u32>) where v=[] is 8,336,361,133 difference for 1 element is 8,336,361,133
Cost of Borsh input of (v: Vec<u32>) where v=[1] is 11,880,003,887 difference for 1 element is 3,543,642,754
Cost of Borsh input of (v: Vec<u32>) where v=[1, 2] is 12,515,942,907 difference for 1 element is 635,939,020
Average diff 635,939,020

@evgenykuzyakov
Copy link
Collaborator

Well, I think I incorrectly implemented the deserialization for fixed size items, need more work on it

@evgenykuzyakov
Copy link
Collaborator

Added a few extra tests

Vec<Vec<u8>>

 -> JSON Inputs <-
Cost of JSON input of (v: Vec<Vec<u8>>) where len(v)=0 is 16,462,246,179
Cost of JSON input of (v: Vec<Vec<u8>>) where len(v)=1 is 68,330,521,396 difference for 1 element is 51,868,275,217
Average diff 52,582,679,666

 -> JSON Outputs <-
Cost of JSON output of Vec<Vec<u8>> where len(v)=0 is 7,370,717,607
Cost of JSON output of Vec<Vec<u8>> where len(v)=1 is 29,451,165,534 difference for 1 element is 22,080,447,927
Average diff 23,725,699,612

 -> Borsh Input <-
Cost of Borsh input of (v: Vec<Vec<u8>>) where len(v)=0 is 9,339,017,593
Cost of Borsh input of (v: Vec<Vec<u8>>) where len(v)=1 is 28,768,075,194 difference for 1 element is 19,429,057,601
Average diff 17,026,152,831

 -> Borsh Outputs <-
Cost of Borsh output of Vec<Vec<u8>> where len(v)=0 is 6,298,894,101
Cost of Borsh output of Vec<Vec<u8>> where len(v)=1 is 14,495,415,900 difference for 1 element is 8,196,521,799
Average diff 7,972,852,281

Vec<String>

 -> JSON Inputs <-
Cost of JSON input of (v: Vec<String>) where len(v)=0 is 16,477,671,663
Cost of JSON input of (v: Vec<String>) where len(v)=1 is 27,055,484,275 difference for 1 element is 10,577,812,612
Average diff 11,277,177,214

 -> JSON Outputs <-
Cost of JSON output of Vec<String> where len(v)=0 is 7,355,292,123
Cost of JSON output of Vec<String> where len(v)=1 is 12,894,650,487 difference for 1 element is 5,539,358,364
Average diff 6,917,363,538

 -> Borsh Input <-
Cost of Borsh input of (v: Vec<String>) where len(v)=0 is 9,339,017,593
Cost of Borsh input of (v: Vec<String>) where len(v)=1 is 20,358,203,587 difference for 1 element is 11,019,185,994
Average diff 8,600,855,740

 -> Borsh Outputs <-
Cost of Borsh output of Vec<String> where len(v)=0 is 6,206,341,197
Cost of Borsh output of Vec<String> where len(v)=1 is 8,842,099,830 difference for 1 element is 2,635,758,633
Average diff 2,412,089,115

@evgenykuzyakov
Copy link
Collaborator

I think Vec<u8> needs to be optimized on borsh side.

@mikedotexe mikedotexe pinned this issue Mar 4, 2020
@evgenykuzyakov
Copy link
Collaborator

Latest metrics with optimized deserialization from Borsh, see near/borsh#58

Input Highlights:

Cost of Borsh input of (s: String) where s="" is 9,080,640,736
Average diff 131,604,521
Cost of Borsh input of (v: Vec) where v=[] is 8,455,908,634
Average diff 112,708,303
Cost of Borsh input of (v: Vec) where v=[] is 8,425,057,666
Average diff 651,364,504

All

Base gas cost of full noop call is 0
Base gas cost of calling a function with near_bindgen is 998,800,089
Extra cost of JSON input for an extra character in an argument name e.g. (aa: u32) vs (a: u32) 351,803,305
 -> INTEGERS <-
 -> JSON Inputs <-
Cost of JSON input of (a: u32) where a=1 is 15,119,355,527
Cost of JSON input of (a: u32) where a=10 is 15,598,419,075 difference for 1 digit is 479,063,548
Cost of JSON input of (a: u32) where a=100 is 16,077,482,623 difference for 1 digit is 479,063,548
Average diff 479,063,548
Cost of JSON input of (a: u32, b: u32) where a=b=1 is 21,797,865,709
Cost of JSON input of (a: u32, b: u32) where a=b=10 is 22,755,992,805 difference for 2 digit is 958,127,096
Cost of JSON input of (a: u32, b: u32) where a=b=100 is 23,779,678,208 difference for 2 digit is 1,023,685,403
Average diff 958,127,096
 -> JSON Outputs <-
Cost of JSON output of u32=1 is 6,024,720,312
Cost of JSON output of u32=10 is 6,105,827,919 difference for 1 digit is 81,107,607
Cost of JSON output of u32=100 is 6,275,632,059 difference for 1 digit is 169,804,140
Average diff 138,953,172
 -> Borsh Input/Output <-
Cost of Borsh input of (a: u32) is 7,946,867,662
Cost of Borsh input of (a: u32, b: u32) is 9,064,853,057
Cost of Borsh output of u32 is 5,824,560,468
 -> STRINGS <-
 -> JSON Inputs <-
Cost of JSON input of (s: String) where s="" is 16,365,836,904
Cost of JSON input of (s: String) where s="h" is 18,584,123,773 difference for 1 char is 2,218,286,869
Cost of JSON input of (s: String) where s="he" is 18,978,347,159 difference for 1 char is 394,223,386
Average diff 237,654,723
 -> JSON Outputs <-
Cost of JSON output of String where s="" is 6,950,373,168
Cost of JSON output of String where s="h" is 7,914,589,734 difference for 1 char is 964,216,566
Cost of JSON output of String where s="he" is 8,099,819,358 difference for 1 char is 185,229,624
Average diff 185,229,624
 -> Borsh Input <-
Cost of Borsh input of (s: String) where s="" is 9,080,640,736
Cost of Borsh input of (s: String) where s="h" is 12,451,982,534 difference for 1 char is 3,371,341,798
Cost of Borsh input of (s: String) where s="he" is 12,618,680,031 difference for 1 char is 166,697,497
Average diff 131,604,521
 -> Borsh Outputs <-
Cost of Borsh output of String where s="" is 6,337,457,811
Cost of Borsh output of String where s="h" is 6,638,378,565 difference for 1 digit is 300,920,754
Cost of Borsh output of String where s="he" is 6,704,060,688 difference for 1 digit is 65,682,123
Average diff 65,682,123
 -> Vec<u8> <-
 -> JSON Inputs <-
Cost of JSON input of (v: Vec<u8>) where v=[] is 15,999,481,659
Cost of JSON input of (v: Vec<u8>) where v=[1] is 20,759,117,017 difference for 1 element is 4,759,635,358
Cost of JSON input of (v: Vec<u8>) where v=[1, 2] is 26,634,990,682 difference for 1 element is 5,875,873,665
Average diff 4,589,656,754
 -> JSON Outputs <-
Cost of JSON output of Vec<u8> where v=[] is 6,973,511,394
Cost of JSON output of Vec<u8> where v=[1] is 8,469,907,158 difference for 1 element is 1,496,395,764
Cost of JSON output of Vec<u8> where v=[1, 2] is 10,259,510,934 difference for 1 element is 1,789,603,776
Average diff 1,773,763,564
 -> Borsh Input <-
Cost of Borsh input of (v: Vec<u8>) where v=[] is 8,455,908,634
Cost of Borsh input of (v: Vec<u8>) where v=[1] is 11,557,304,462 difference for 1 element is 3,101,395,828
Cost of Borsh input of (v: Vec<u8>) where v=[1, 2] is 11,670,012,765 difference for 1 element is 112,708,303
Average diff 112,708,303
 -> Borsh Outputs <-
Cost of Borsh output of Vec<u8> where v=[] is 6,025,091,760
Cost of Borsh output of Vec<u8> where v=[1] is 6,815,771,631 difference for 1 element is 790,679,871
Cost of Borsh output of Vec<u8> where v=[1, 2] is 7,382,781,984 difference for 1 element is 567,010,353
Average diff 567,010,353
 -> Vec<u32> <-
 -> JSON Inputs <-
Cost of JSON input of (v: Vec<u32>) where v=[] is 15,964,774,320
Cost of JSON input of (v: Vec<u32>) where v=[1] is 20,982,786,535 difference for 1 element is 5,018,012,215
Cost of JSON input of (v: Vec<u32>) where v=[1, 2] is 27,313,711,978 difference for 1 element is 6,330,925,443
Average diff 5,062,276,444
 -> JSON Outputs <-
Cost of JSON output of Vec<u32> where v=[] is 6,757,554,618
Cost of JSON output of Vec<u32> where v=[1] is 8,454,481,674 difference for 1 element is 1,696,927,056
Cost of JSON output of Vec<u32> where v=[1, 2] is 10,444,616,742 difference for 1 element is 1,990,135,068
Average diff 1,975,151,827
 -> Borsh Input <-
Cost of Borsh input of (v: Vec<u32>) where v=[] is 8,425,057,666
Cost of Borsh input of (v: Vec<u32>) where v=[1] is 11,691,041,708 difference for 1 element is 3,265,984,042
Cost of Borsh input of (v: Vec<u32>) where v=[1, 2] is 12,342,406,212 difference for 1 element is 651,364,504
Average diff 651,364,504
 -> Borsh Outputs <-
Cost of Borsh output of Vec<u32> where v=[] is 5,789,853,129
Cost of Borsh output of Vec<u32> where v=[1] is 6,927,977,838 difference for 1 element is 1,138,124,709
Cost of Borsh output of Vec<u32> where v=[1, 2] is 7,842,433,029 difference for 1 element is 914,455,191
Average diff 914,455,191
 -> Vec<Vec<u8>> <-
 -> JSON Inputs <-
Cost of JSON input of (v: Vec<Vec<u8>>) where len(v)=0 is 16,277,140,371
Cost of JSON input of (v: Vec<Vec<u8>>) where len(v)=1 is 68,029,724,458 difference for 1 element is 51,752,584,087
Cost of JSON input of (v: Vec<Vec<u8>>) where len(v)=2 is 121,577,268,148 difference for 1 element is 53,547,543,690
Average diff 52,466,988,536
 -> JSON Outputs <-
Cost of JSON output of Vec<Vec<u8>> where len(v)=0 is 6,911,809,458
Cost of JSON output of Vec<Vec<u8>> where len(v)=1 is 26,805,695,028 difference for 1 element is 19,893,885,570
Cost of JSON output of Vec<Vec<u8>> where len(v)=2 is 47,208,745,386 difference for 1 element is 20,403,050,358
Average diff 21,435,015,238
 -> Borsh Input <-
Cost of Borsh input of (v: Vec<Vec<u8>>) where len(v)=0 is 8,498,328,715
Cost of Borsh input of (v: Vec<Vec<u8>>) where len(v)=1 is 16,678,352,109 difference for 1 element is 8,180,023,394
Cost of Borsh input of (v: Vec<Vec<u8>>) where len(v)=2 is 22,613,967,581 difference for 1 element is 5,935,615,472
Average diff 5,973,793,545
 -> Borsh Outputs <-
Cost of Borsh output of Vec<Vec<u8>> where len(v)=0 is 5,944,107,969
Cost of Borsh output of Vec<Vec<u8>> where len(v)=1 is 12,995,287,581 difference for 1 element is 7,051,179,612
Cost of Borsh output of Vec<Vec<u8>> where len(v)=2 is 19,822,797,675 difference for 1 element is 6,827,510,094
Average diff 6,827,510,094
 -> Vec<String> <-
 -> JSON Inputs <-
Cost of JSON input of (v: Vec<String>) where len(v)=0 is 16,292,565,855
Cost of JSON input of (v: Vec<String>) where len(v)=1 is 26,770,112,821 difference for 1 element is 10,477,546,966
Cost of JSON input of (v: Vec<String>) where len(v)=2 is 39,112,034,068 difference for 1 element is 12,341,921,247
Average diff 11,176,911,568
 -> JSON Outputs <-
Cost of JSON output of Vec<String> where len(v)=0 is 6,896,383,974
Cost of JSON output of Vec<String> where len(v)=1 is 12,123,376,287 difference for 1 element is 5,226,992,313
Cost of JSON output of Vec<String> where len(v)=2 is 17,859,533,388 difference for 1 element is 5,736,157,101
Average diff 6,500,875,470
 -> Borsh Input <-
Cost of Borsh input of (v: Vec<String>) where len(v)=0 is 8,498,328,715
Cost of Borsh input of (v: Vec<String>) where len(v)=1 is 17,789,860,501 difference for 1 element is 9,291,531,786
Cost of Borsh input of (v: Vec<String>) where len(v)=2 is 24,821,558,881 difference for 1 element is 7,031,698,380
Average diff 7,069,876,453
 -> Borsh Outputs <-
Cost of Borsh output of Vec<String> where len(v)=0 is 5,851,555,065
Cost of Borsh output of Vec<String> where len(v)=1 is 8,279,069,664 difference for 1 element is 2,427,514,599
Cost of Borsh output of Vec<String> where len(v)=2 is 10,482,914,745 difference for 1 element is 2,203,845,081
Average diff 2,203,845,081
 -> SIMPLE STRUCT <-
Extra cost of JSON input of {"a": {"a": 1}} vs {"a": 1} 5,678,836,549
Extra cost of JSON output of {"a": {"a": 1}} vs {"a": 1} 5,318,678,505
Extra cost of Borsh input of {"a": {"a": 1}} vs {"a": 1} 115,691,130
Extra cost of Borsh output of {"a": {"a": 1}} vs {"a": 1} 158,111,211

evgenykuzyakov pushed a commit to near/borsh that referenced this issue Mar 13, 2020
Optimizing strings/vec<u8> reads using custom implementation for `Vec<u8>` with a bit of unsafe code, but without UB.
Switching deserialization to use `&mut &[u8]` instead of `BufRead`. It allows us to switch to `BorshError` instead of `std::io::Error` in the future to go with `no_std`.

# Test plan

- Added unit tests for `String` and `Vec<T>`
- Verified gas cost by linking borsh directly to gas fee meter. See near/nearcore#1829 
- Re-running benchmarks
evgenykuzyakov pushed a commit to near/near-sdk-rs that referenced this issue Mar 14, 2020
Added an example to run NEAR Runtime standalone runner to compare gas fess between different serialization methods and computing average gas usage per byte/number/element  

Issue: near/nearcore#1829
@MaksymZavershynskyi MaksymZavershynskyi removed this from the MainNet milestone Mar 20, 2020
@ilblackdragon ilblackdragon added this to the Post MainNet milestone Mar 20, 2020
@MaksymZavershynskyi MaksymZavershynskyi removed this from the Post MainNet milestone Mar 21, 2020
@MaksymZavershynskyi
Copy link
Contributor Author

We made some important gas measurements. The rest is not crucial for the Mainnet launch. Moving to the Ice Box.

@mikhailOK mikhailOK unpinned this issue Apr 1, 2020
volovyks pushed a commit to near/borsh-js that referenced this issue Nov 30, 2020
Optimizing strings/vec<u8> reads using custom implementation for `Vec<u8>` with a bit of unsafe code, but without UB.
Switching deserialization to use `&mut &[u8]` instead of `BufRead`. It allows us to switch to `BorshError` instead of `std::io::Error` in the future to go with `no_std`.

# Test plan

- Added unit tests for `String` and `Vec<T>`
- Verified gas cost by linking borsh directly to gas fee meter. See near/nearcore#1829 
- Re-running benchmarks
volovyks pushed a commit to near/borsh-js that referenced this issue Nov 30, 2020
Optimizing strings/vec<u8> reads using custom implementation for `Vec<u8>` with a bit of unsafe code, but without UB.
Switching deserialization to use `&mut &[u8]` instead of `BufRead`. It allows us to switch to `BorshError` instead of `std::io::Error` in the future to go with `no_std`.

# Test plan

- Added unit tests for `String` and `Vec<T>`
- Verified gas cost by linking borsh directly to gas fee meter. See near/nearcore#1829 
- Re-running benchmarks
@stale
Copy link

stale bot commented Jul 1, 2021

This issue has been automatically marked as stale because it has not had recent activity in the last 2 months.
It will be closed in 7 days if no further activity occurs.
Thank you for your contributions.

@stale stale bot added the S-stale label Jul 1, 2021
@bowenwang1996
Copy link
Collaborator

@evgenykuzyakov are there still any action items here? if not let's close the issue

@stale stale bot removed the S-stale label Jul 2, 2021
@stale
Copy link

stale bot commented Sep 30, 2021

This issue has been automatically marked as stale because it has not had recent activity in the last 2 months.
It will be closed in 7 days if no further activity occurs.
Thank you for your contributions.

@stale stale bot added the S-stale label Sep 30, 2021
@bowenwang1996
Copy link
Collaborator

Duplicate of #2501

@bowenwang1996 bowenwang1996 marked this as a duplicate of #2501 Oct 1, 2021
tiger1028 added a commit to tiger1028/near-sdk-rs that referenced this issue Dec 24, 2024
Added an example to run NEAR Runtime standalone runner to compare gas fess between different serialization methods and computing average gas usage per byte/number/element  

Issue: near/nearcore#1829
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-transaction-runtime Area: transaction runtime (transaction and receipts processing, state transition, etc) C-epic Category: an epic P-low Priority: low
Projects
None yet
Development

No branches or pull requests

5 participants