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

tools: Add linter rule for goconst. #398

Merged
merged 5 commits into from
May 20, 2022

Conversation

shahzadlone
Copy link
Member

@shahzadlone shahzadlone commented May 5, 2022

RELATED ISSUE(S):

Resolves #403

DESCRIPTION:

Enables the goconst linter and and resolves all it's errors.

This was one of the remaining linters we didn't have enabled from the list of recommended ones that were mentioned in the book 100 go mistakes and how to avoid them.

One side affect of this PR was that schema package was decoupled from using the parser package.

@shahzadlone shahzadlone added the code quality Related to improving code quality label May 5, 2022
@shahzadlone shahzadlone added this to the DefraDB v0.3 milestone May 5, 2022
@shahzadlone shahzadlone self-assigned this May 5, 2022
@codecov
Copy link

codecov bot commented May 5, 2022

Codecov Report

Merging #398 (34ec25a) into develop (fd76c5c) will increase coverage by 0.04%.
The diff coverage is 89.23%.

❗ Current head 34ec25a differs from pull request most recent head efdf778. Consider uploading reports for the commit efdf778 to get more accurate results

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #398      +/-   ##
===========================================
+ Coverage    64.94%   64.99%   +0.04%     
===========================================
  Files           86       86              
  Lines        10001    10015      +14     
===========================================
+ Hits          6495     6509      +14     
  Misses        2867     2867              
  Partials       639      639              
Impacted Files Coverage Δ
query/graphql/planner/render.go 86.95% <33.33%> (ø)
query/graphql/parser/query.go 80.06% <82.75%> (+0.06%) ⬆️
query/graphql/parser/commit.go 59.61% <83.33%> (ø)
logging/logger.go 83.01% <85.71%> (+0.66%) ⬆️
query/graphql/planner/select.go 75.41% <87.50%> (ø)
query/graphql/schema/descriptions.go 86.48% <87.50%> (+0.87%) ⬆️
db/collection_delete.go 61.67% <100.00%> (ø)
query/graphql/parser/filter.go 69.60% <100.00%> (ø)
query/graphql/parser/mutation.go 60.18% <100.00%> (ø)
query/graphql/planner/group.go 79.06% <100.00%> (ø)
... and 6 more

@shahzadlone shahzadlone force-pushed the lone/tools/add-goconst-linter branch from 3f87834 to 394c0f9 Compare May 5, 2022 09:38
@source-devs
Copy link

Benchmark Results

Summary

  • 113 Benchmarks successfully compared.
  • 14 Benchmarks were ✅ Better.
  • 99 Benchmarks were ❌ Worse .
  • 0 Benchmarks were ✨ Unchanged.
✅ See Better Results...
time/opdelta
_Collection_UserSimple_CreateMany_Sync_0_100-4265ms ± 0%258ms ± 0%−2.54%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Sync_0_10-412.6ms ± 0%10.9ms ± 0%−13.36%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Sync_0_100-4126ms ± 0%124ms ± 0%−1.69%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Sync_0_1000-41.15s ± 0%1.10s ± 0%−4.28%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Async_0_1000-4475ms ± 0%471ms ± 0%−1.00%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Async_0_10000-44.84s ± 0%4.84s ± 0%−0.02%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_10_10-4394µs ± 0%384µs ± 0%−2.51%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_100_100-44.54ms ± 0%4.27ms ± 0%−5.94%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_1000_10-4390µs ± 0%373µs ± 0%−4.33%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithLimitOffset_Sync_1000-4478µs ± 0%466µs ± 0%−2.68%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0512-4220µs ± 0%211µs ± 0%−3.84%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0064-41.30ms ± 0%1.21ms ± 0%−6.46%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:1024-4139µs ± 0%137µs ± 0%−1.26%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0256-41.44ms ± 0%1.44ms ± 0%−0.07%(p=1.000 n=1+1)
 
❌ See Worse Results...
time/opdelta
_Collection_UserSimple_Create_Async_0_100-449.2ms ± 0%49.9ms ± 0%+1.38%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_1000_1000-440.9ms ± 0%42.8ms ± 0%+4.53%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_1000_100-44.03ms ± 0%4.80ms ± 0%+19.10%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_10_10-4289µs ± 0%360µs ± 0%+24.38%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_100_100-41.85ms ± 0%2.14ms ± 0%+15.29%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_1000_1000-424.4ms ± 0%25.4ms ± 0%+3.82%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_1000_10-4259µs ± 0%302µs ± 0%+16.41%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_1000_100-41.91ms ± 0%2.57ms ± 0%+34.10%(p=1.000 n=1+1)
_Query_UserSimple_Query_Sync_100-41.25ms ± 0%1.55ms ± 0%+24.50%(p=1.000 n=1+1)
_Query_UserSimple_Query_Sync_1000-49.75ms ± 0%10.83ms ± 0%+11.08%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithFilter_Sync_10-4482µs ± 0%569µs ± 0%+17.94%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithFilter_Sync_100-41.31ms ± 0%1.70ms ± 0%+29.68%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithFilter_Sync_1000-410.2ms ± 0%14.6ms ± 0%+43.65%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithLimitOffset_Sync_10-4470µs ± 0%632µs ± 0%+34.52%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithLimitOffset_Sync_100-4531µs ± 0%698µs ± 0%+31.49%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithMultiLookup_Sync_10-4710µs ± 0%853µs ± 0%+20.20%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithMultiLookup_Sync_100-4711µs ± 0%905µs ± 0%+27.34%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithMultiLookup_Sync_1000-4656µs ± 0%685µs ± 0%+4.48%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSingleLookup_Sync_10-4321µs ± 0%380µs ± 0%+18.47%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSingleLookup_Sync_100-4342µs ± 0%355µs ± 0%+3.80%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSingleLookup_Sync_1000-4277µs ± 0%278µs ± 0%+0.40%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSort_Sync_10-4484µs ± 0%536µs ± 0%+10.69%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSort_Sync_100-41.47ms ± 0%1.57ms ± 0%+6.63%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSort_Sync_1000-412.3ms ± 0%13.0ms ± 0%+5.38%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:0128-414.9µs ± 0%17.6µs ± 0%+18.15%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:0256-414.0µs ± 0%19.1µs ± 0%+36.69%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:0512-417.6µs ± 0%20.8µs ± 0%+17.83%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:1024-420.2µs ± 0%26.3µs ± 0%+30.43%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0064-4148µs ± 0%152µs ± 0%+2.71%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0128-4136µs ± 0%158µs ± 0%+16.51%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0256-4148µs ± 0%170µs ± 0%+14.84%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0512-4182µs ± 0%196µs ± 0%+7.83%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:1024-4211µs ± 0%281µs ± 0%+33.35%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0064-417.1µs ± 0%21.0µs ± 0%+22.76%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0128-417.4µs ± 0%17.5µs ± 0%+0.85%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0256-415.7µs ± 0%19.1µs ± 0%+21.38%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0512-419.0µs ± 0%30.6µs ± 0%+60.89%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:1024-424.0µs ± 0%29.4µs ± 0%+22.55%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0064-4161µs ± 0%189µs ± 0%+17.47%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0128-4170µs ± 0%178µs ± 0%+4.98%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0256-4186µs ± 0%194µs ± 0%+4.10%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:1024-4248µs ± 0%265µs ± 0%+6.87%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0064-448.3µs ± 0%65.0µs ± 0%+34.63%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0128-454.9µs ± 0%61.9µs ± 0%+12.81%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0256-456.8µs ± 0%61.8µs ± 0%+8.83%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0512-463.9µs ± 0%66.5µs ± 0%+4.11%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:1024-476.9µs ± 0%95.9µs ± 0%+24.81%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0064-4364µs ± 0%450µs ± 0%+23.52%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0128-4392µs ± 0%452µs ± 0%+15.10%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0256-4389µs ± 0%465µs ± 0%+19.43%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0512-4428µs ± 0%478µs ± 0%+11.77%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:1024-4526µs ± 0%619µs ± 0%+17.80%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0064-444.4µs ± 0%71.9µs ± 0%+61.87%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0128-449.4µs ± 0%78.4µs ± 0%+58.77%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0256-449.4µs ± 0%60.4µs ± 0%+22.15%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0512-456.2µs ± 0%71.4µs ± 0%+27.03%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:1024-471.0µs ± 0%90.0µs ± 0%+26.76%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0064-4354µs ± 0%548µs ± 0%+55.03%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0128-4383µs ± 0%465µs ± 0%+21.50%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0256-4422µs ± 0%509µs ± 0%+20.49%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0512-4450µs ± 0%578µs ± 0%+28.40%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:1024-4579µs ± 0%633µs ± 0%+9.38%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0064-4117µs ± 0%155µs ± 0%+33.03%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0128-4123µs ± 0%162µs ± 0%+31.64%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0256-4127µs ± 0%166µs ± 0%+30.16%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0512-4138µs ± 0%171µs ± 0%+23.23%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:1024-4168µs ± 0%204µs ± 0%+21.83%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0064-41.35ms ± 0%1.95ms ± 0%+44.94%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0128-41.45ms ± 0%1.56ms ± 0%+7.48%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0256-41.41ms ± 0%1.94ms ± 0%+36.95%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0512-41.32ms ± 0%1.87ms ± 0%+41.63%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:1024-41.41ms ± 0%2.00ms ± 0%+41.58%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0064-4119µs ± 0%156µs ± 0%+31.34%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0128-4117µs ± 0%159µs ± 0%+35.06%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0256-4128µs ± 0%170µs ± 0%+32.15%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0512-4124µs ± 0%171µs ± 0%+37.96%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:1024-4136µs ± 0%200µs ± 0%+46.64%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0128-41.22ms ± 0%1.23ms ± 0%+0.73%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0256-41.21ms ± 0%1.30ms ± 0%+7.54%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0512-41.28ms ± 0%1.35ms ± 0%+5.72%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:1024-41.45ms ± 0%1.77ms ± 0%+22.28%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0064-48.66µs ± 0%12.41µs ± 0%+43.34%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0128-48.68µs ± 0%10.83µs ± 0%+24.82%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0256-410.1µs ± 0%11.2µs ± 0%+10.57%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0512-412.5µs ± 0%14.8µs ± 0%+18.46%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:1024-415.8µs ± 0%24.0µs ± 0%+52.58%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0064-494.6µs ± 0%123.1µs ± 0%+30.22%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0128-498.8µs ± 0%138.3µs ± 0%+39.91%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0256-4105µs ± 0%125µs ± 0%+19.28%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0512-4126µs ± 0%165µs ± 0%+31.20%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:1024-4165µs ± 0%214µs ± 0%+29.69%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0064-4129µs ± 0%144µs ± 0%+11.87%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0128-4129µs ± 0%139µs ± 0%+7.30%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0256-4130µs ± 0%135µs ± 0%+3.80%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0512-4132µs ± 0%142µs ± 0%+6.96%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0064-41.23ms ± 0%1.32ms ± 0%+7.38%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0128-41.25ms ± 0%1.32ms ± 0%+5.69%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0512-41.40ms ± 0%1.41ms ± 0%+0.92%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:1024-41.35ms ± 0%1.61ms ± 0%+19.22%(p=1.000 n=1+1)
 
✨ See Unchanged Results...
time/opdelta
 
🐋 See Full Results...
develop.txtcurrent.txt
time/opdelta
pkg:github.com/sourcenetwork/defradb/bench/collection goos:linux goarch:amd64
_Collection_UserSimple_CreateMany_Sync_0_10-411.2ms ± 0%12.4ms ± 0%+10.75%(p=1.000 n=1+1)
_Collection_UserSimple_CreateMany_Sync_0_100-4265ms ± 0%258ms ± 0%−2.54%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Sync_0_10-412.6ms ± 0%10.9ms ± 0%−13.36%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Sync_0_100-4126ms ± 0%124ms ± 0%−1.69%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Sync_0_1000-41.15s ± 0%1.10s ± 0%−4.28%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Async_0_100-449.2ms ± 0%49.9ms ± 0%+1.38%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Async_0_1000-4475ms ± 0%471ms ± 0%−1.00%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Async_0_10000-44.84s ± 0%4.84s ± 0%−0.02%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_10_10-4394µs ± 0%384µs ± 0%−2.51%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_100_100-44.54ms ± 0%4.27ms ± 0%−5.94%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_1000_1000-440.9ms ± 0%42.8ms ± 0%+4.53%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_1000_10-4390µs ± 0%373µs ± 0%−4.33%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_1000_100-44.03ms ± 0%4.80ms ± 0%+19.10%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_10_10-4289µs ± 0%360µs ± 0%+24.38%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_100_100-41.85ms ± 0%2.14ms ± 0%+15.29%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_1000_1000-424.4ms ± 0%25.4ms ± 0%+3.82%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_1000_10-4259µs ± 0%302µs ± 0%+16.41%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_1000_100-41.91ms ± 0%2.57ms ± 0%+34.10%(p=1.000 n=1+1)
pkg:github.com/sourcenetwork/defradb/bench/query/simple goos:linux goarch:amd64
_Query_UserSimple_Query_Sync_10-4370µs ± 0%414µs ± 0%+11.80%(p=1.000 n=1+1)
_Query_UserSimple_Query_Sync_100-41.25ms ± 0%1.55ms ± 0%+24.50%(p=1.000 n=1+1)
_Query_UserSimple_Query_Sync_1000-49.75ms ± 0%10.83ms ± 0%+11.08%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithFilter_Sync_10-4482µs ± 0%569µs ± 0%+17.94%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithFilter_Sync_100-41.31ms ± 0%1.70ms ± 0%+29.68%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithFilter_Sync_1000-410.2ms ± 0%14.6ms ± 0%+43.65%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithLimitOffset_Sync_10-4470µs ± 0%632µs ± 0%+34.52%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithLimitOffset_Sync_100-4531µs ± 0%698µs ± 0%+31.49%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithLimitOffset_Sync_1000-4478µs ± 0%466µs ± 0%−2.68%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithMultiLookup_Sync_10-4710µs ± 0%853µs ± 0%+20.20%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithMultiLookup_Sync_100-4711µs ± 0%905µs ± 0%+27.34%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithMultiLookup_Sync_1000-4656µs ± 0%685µs ± 0%+4.48%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSingleLookup_Sync_10-4321µs ± 0%380µs ± 0%+18.47%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSingleLookup_Sync_100-4342µs ± 0%355µs ± 0%+3.80%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSingleLookup_Sync_1000-4277µs ± 0%278µs ± 0%+0.40%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSort_Sync_10-4484µs ± 0%536µs ± 0%+10.69%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSort_Sync_100-41.47ms ± 0%1.57ms ± 0%+6.63%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSort_Sync_1000-412.3ms ± 0%13.0ms ± 0%+5.38%(p=1.000 n=1+1)
pkg:github.com/sourcenetwork/defradb/bench/storage goos:linux goarch:amd64
_Storage_Simple_Read_Sync_1_10/ValueSize:0064-414.1µs ± 0%18.7µs ± 0%+33.01%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:0128-414.9µs ± 0%17.6µs ± 0%+18.15%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:0256-414.0µs ± 0%19.1µs ± 0%+36.69%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:0512-417.6µs ± 0%20.8µs ± 0%+17.83%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:1024-420.2µs ± 0%26.3µs ± 0%+30.43%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0064-4148µs ± 0%152µs ± 0%+2.71%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0128-4136µs ± 0%158µs ± 0%+16.51%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0256-4148µs ± 0%170µs ± 0%+14.84%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0512-4182µs ± 0%196µs ± 0%+7.83%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:1024-4211µs ± 0%281µs ± 0%+33.35%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0064-417.1µs ± 0%21.0µs ± 0%+22.76%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0128-417.4µs ± 0%17.5µs ± 0%+0.85%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0256-415.7µs ± 0%19.1µs ± 0%+21.38%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0512-419.0µs ± 0%30.6µs ± 0%+60.89%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:1024-424.0µs ± 0%29.4µs ± 0%+22.55%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0064-4161µs ± 0%189µs ± 0%+17.47%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0128-4170µs ± 0%178µs ± 0%+4.98%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0256-4186µs ± 0%194µs ± 0%+4.10%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0512-4220µs ± 0%211µs ± 0%−3.84%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:1024-4248µs ± 0%265µs ± 0%+6.87%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0064-448.3µs ± 0%65.0µs ± 0%+34.63%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0128-454.9µs ± 0%61.9µs ± 0%+12.81%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0256-456.8µs ± 0%61.8µs ± 0%+8.83%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0512-463.9µs ± 0%66.5µs ± 0%+4.11%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:1024-476.9µs ± 0%95.9µs ± 0%+24.81%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0064-4364µs ± 0%450µs ± 0%+23.52%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0128-4392µs ± 0%452µs ± 0%+15.10%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0256-4389µs ± 0%465µs ± 0%+19.43%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0512-4428µs ± 0%478µs ± 0%+11.77%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:1024-4526µs ± 0%619µs ± 0%+17.80%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0064-444.4µs ± 0%71.9µs ± 0%+61.87%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0128-449.4µs ± 0%78.4µs ± 0%+58.77%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0256-449.4µs ± 0%60.4µs ± 0%+22.15%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0512-456.2µs ± 0%71.4µs ± 0%+27.03%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:1024-471.0µs ± 0%90.0µs ± 0%+26.76%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0064-4354µs ± 0%548µs ± 0%+55.03%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0128-4383µs ± 0%465µs ± 0%+21.50%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0256-4422µs ± 0%509µs ± 0%+20.49%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0512-4450µs ± 0%578µs ± 0%+28.40%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:1024-4579µs ± 0%633µs ± 0%+9.38%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0064-4117µs ± 0%155µs ± 0%+33.03%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0128-4123µs ± 0%162µs ± 0%+31.64%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0256-4127µs ± 0%166µs ± 0%+30.16%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0512-4138µs ± 0%171µs ± 0%+23.23%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:1024-4168µs ± 0%204µs ± 0%+21.83%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0064-41.35ms ± 0%1.95ms ± 0%+44.94%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0128-41.45ms ± 0%1.56ms ± 0%+7.48%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0256-41.41ms ± 0%1.94ms ± 0%+36.95%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0512-41.32ms ± 0%1.87ms ± 0%+41.63%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:1024-41.41ms ± 0%2.00ms ± 0%+41.58%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0064-4119µs ± 0%156µs ± 0%+31.34%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0128-4117µs ± 0%159µs ± 0%+35.06%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0256-4128µs ± 0%170µs ± 0%+32.15%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0512-4124µs ± 0%171µs ± 0%+37.96%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:1024-4136µs ± 0%200µs ± 0%+46.64%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0064-41.30ms ± 0%1.21ms ± 0%−6.46%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0128-41.22ms ± 0%1.23ms ± 0%+0.73%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0256-41.21ms ± 0%1.30ms ± 0%+7.54%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0512-41.28ms ± 0%1.35ms ± 0%+5.72%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:1024-41.45ms ± 0%1.77ms ± 0%+22.28%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0064-48.66µs ± 0%12.41µs ± 0%+43.34%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0128-48.68µs ± 0%10.83µs ± 0%+24.82%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0256-410.1µs ± 0%11.2µs ± 0%+10.57%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0512-412.5µs ± 0%14.8µs ± 0%+18.46%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:1024-415.8µs ± 0%24.0µs ± 0%+52.58%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0064-494.6µs ± 0%123.1µs ± 0%+30.22%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0128-498.8µs ± 0%138.3µs ± 0%+39.91%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0256-4105µs ± 0%125µs ± 0%+19.28%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0512-4126µs ± 0%165µs ± 0%+31.20%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:1024-4165µs ± 0%214µs ± 0%+29.69%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0064-4129µs ± 0%144µs ± 0%+11.87%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0128-4129µs ± 0%139µs ± 0%+7.30%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0256-4130µs ± 0%135µs ± 0%+3.80%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0512-4132µs ± 0%142µs ± 0%+6.96%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:1024-4139µs ± 0%137µs ± 0%−1.26%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0064-41.23ms ± 0%1.32ms ± 0%+7.38%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0128-41.25ms ± 0%1.32ms ± 0%+5.69%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0256-41.44ms ± 0%1.44ms ± 0%−0.07%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0512-41.40ms ± 0%1.41ms ± 0%+0.92%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:1024-41.35ms ± 0%1.61ms ± 0%+19.22%(p=1.000 n=1+1)
 

@shahzadlone shahzadlone requested review from AndrewSisley, jsimnz, fredcarle and orpheuslummis and removed request for AndrewSisley May 5, 2022 10:47
Copy link
Contributor

@orpheuslummis orpheuslummis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sourcenetwork sourcenetwork deleted a comment from source-devs May 5, 2022
@sourcenetwork sourcenetwork deleted a comment from source-devs May 5, 2022
Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one optional change: add string to your const declarations.

const key_1 string = "/p/0/0/k1"

It's just to help the compiler a little.

@@ -16,6 +16,28 @@ import (
"github.com/stretchr/testify/assert"
)

const (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: I really dont think this makes reading the tests easier. Suggest a bit of a rethink and consider skipping the test files for this rule if that is possible

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am of the same opinion

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dam... I looked at this without thinking about the fact that this is a test file 🤦‍♂️

I agree. This list of constants doesn't really improve anything here. Maybe a map of the keys instead?

Copy link
Member Author

@shahzadlone shahzadlone May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not make tests easier but definitely doesn't make them harder to read either. In my opinion this still gives most of the benefits of having constant defined strings that you would have in non-test code as well. Some of these nice attributes to a new person coming to this test file might be:

  1. Better insight to common string literals. For example the key being used on line 429 and on line 65 are the same, it's obvious to spot that this way. However if it was instead this on line 65 "/p/0/0/k2" and this on line 429 "/p/0/0/K2" it is very easy to miss the difference (capitalized 'K' on the second one).

  2. When I first looked at this file I wondered how many unique keys are being used in the test (no good reason why lol), but having them defined in one place it's easy to see.

I would say in this case the linter rule is very easy to add and maintain even for the test files.

However open to hear what others think as well, as it might just be my love for constants making me biased here haha.

@fredcarle @jsimnz opinions?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To Andy's point, it doesn't make reading the tests easier. Also tests are in isolation of one another so you don't gain much by having global const/var if there are no duplication of the strings within the test functions themselves.

In test files, I'd rather see an array or a map that you can loop through (if it makes sense to do so). Unless there are many instances of the same string in the one function, then it makes sense to assign to a scoped variable.

The more I look at the file to question my own opinion, the less I like to see the constants being use as values to variables that are then used as value parameters to functions. I'll sleep on it and see if I can come up with something helpful in the morning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not make tests easier but definitely doesn't make them harder to read either.

Yes it does. You can no longer see the values under test and instead have to scroll up (potentially a few hundred lines) to view them. It can also couple tests together if they are mindlessly shared between them. And it creates a meaningless block of nonsense at the top of the file.

Copy link
Member Author

@shahzadlone shahzadlone May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does. You can no longer see the values under test and instead have to scroll up (potentially a few hundred lines) to view them. It can also couple tests together if they are mindlessly shared between them. And it creates a meaningless block of nonsense at the top of the file.

As that seems like the general consensus, will turn this rule off for tests.

  • Removed the linter rule from all test files.

@shahzadlone
Copy link
Member Author

LGTM with one optional change: add string to your const declarations.

const key_1 string = "/p/0/0/k1"

It's just to help the compiler a little.

Yes I noticed that when I put the string it infers the type properly otherwise it says untyped on something. Will add that if we decide to keep it for tests as well. Is this common / good practice for inferring literals variables in go?

@fredcarle
Copy link
Collaborator

Is this common / good practice for inferring literals variables in go?

For const yes. For var no.

@shahzadlone
Copy link
Member Author

Is this common / good practice for inferring literals variables in go?

For const yes. For var no.

Awesome thanks for sharing the tip, will add it to my go development jar of tips.

@shahzadlone shahzadlone force-pushed the lone/tools/add-goconst-linter branch from 394c0f9 to 0e68988 Compare May 10, 2022 00:05
@source-devs

This comment was marked as off-topic.

Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers for excluding the tests, and sorry about the hassle here but I have another request

package parser

const (
cidProperty = "cid"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Sorry I'm a bit late on this one, but in my opinion 'Property' is quite ambiguous and we could name these a bit better. Or type alias them perhap?

type InputArgName string
const (
    cidInputArgName = InputArgName("cid")
    dataInputArgName = ...
)

Or perhaps even move them (and similar items) to a new sub package of client where we hold the public query components.

Sorry about the hassle, but I do not want us to move these some place poorly for the sake of a linter rule. The rules should only ever force us to make things better and we should avoid finding quick satisfactions to them, even if that makes introducing new rules a bit more painful/tedious.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: If we are going to type alias them, we can remove the type from the const name.

The name of the variable should describe its contents, not the type of the contents.

See here for more details.

Copy link
Contributor

@AndrewSisley AndrewSisley May 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I dont like the type in name stuff either, but here it could be seen as more of a linguistic coincidence. cidInputArgName is the CID Input Argument Name. Having a global cid is very ambiguous, especially as it easily clashes with local variables (e.g. you have a local/temp var cid that is actually a cid). In C#/JS/etc. I would have scoped/namespaced these in a struct or similar, but unsure how to best handle it in Go:

pub class InputArgNames {
   const Cid string = "cid"
}

fn foo() {
   ...
   bar[InputArgNames.Cid] = cid
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Sorry I'm a bit late on this one, but in my opinion 'Property' is quite ambiguous and we could name these a bit better. Or type alias them perhap?

type InputArgName string
const (
    cidInputArgName = InputArgName("cid")
    dataInputArgName = ...
)

Or perhaps even move them (and similar items) to a new sub package of client where we hold the public query components.

Sorry about the hassle, but I do not want us to move these some place poorly for the sake of a linter rule. The rules should only ever force us to make things better and we should avoid finding quick satisfactions to them, even if that makes introducing new rules a bit more painful/tedious.

You are not late at all and dw it's no hassle, like you mentioned the goal is to make things better even if it takes a longer more tedious route and many changes. I actually didn't know what a more idiomatic approach is so I just tucked them in that file for now.

Copy link
Member Author

@shahzadlone shahzadlone May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things I don't like from the current approach is just as you boys also have mentioned that extra 'Type' added to the name, this I usually get around in C++ by using enum classes or a C++ namespace (like Andy mentioned aswell).

Unfortunately, Go doesn't have const enum classes or namespaces but recommends using sub-packages to achieve the namespace effect like we currently have here: https://github.com/sourcenetwork/defradb/blob/develop/query/graphql/schema/types/types.go
However in a discussion with John, he mentioned it can be just flattened outside into the schema package, as we have a few other files with similar constant that would then all require nano subpackages.

Here I can highlight another solution I came across, and we can discuss which one we should adopt until Go comes up with something cleaner...

Using anonymous struct:

var InputPropertyName = struct {
    Cid  string
    Data string
}{
    Cid  : "cid",
    Data : "data",
}

// usage example
var cid := InputPropertyName.Cid

Using anonymous struct with type alias:

type InputPropertyNameType string

var InputPropertyName = struct {
    Cid  InputPropertyNameType
    Data InputPropertyNameType
}{
    Cid  : InputPropertyNameType("cid"),
    Data : InputPropertyNameType("data"),
}

// usage example
var cid := InputPropertyName.Cid

One thing I don't like with above is how you have to type each identifier multiple types. However willing to bite the bullet for that namespacing effect.

LMK, which ones you boys prefer?

  1. Using anonymous struct with type alias.
  2. Using anonymous struct.
  3. Nano-sub packages.
  4. Separate file in package, like we already have (no namespace).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty against most uses of anonymous structs, especially for globals, since you lose a lot of type information.

I could get behind a more thought out type nano sub package.

I'm also quite fine with keeping these const/var globals in the parser package, but it would be work to properly name them since they are somewhat generic (ie: cid)

So I would prob suggest nano package approach as you described it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a sub-package seems to be a clear way to create namespace, at the negligible cost of having a bit more clutter and bit more 'distance'.

Otherwise, the status quo doesnt seems bad to me (considering the alternatives): keep them in-package using a naming convention. The suffixProperty, while ambiguous taken alone, seems clear enough in context.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright boys. I've had enough time to debate this with myself that I think I can add my comment.

First, just to get this out of the way, the only times I will use an anonymous struct is for a test function or in rare occasions where that struct is only needed inside a single function, and having a type would be irrelevant.

As for my recommendation for the list of constants, my preferred solution would be to keep the constants here but in the following form:

type queryArg string

const (
	typeCID     = queryArg("cid")
	typeData    = queryArg("data")
	typeDocKey  = queryArg("dockey")
	typeDocKeys = queryArg("dockeys")
	typeField   = queryArg("field")
	typeID      = queryArg("id")
	typeIDs     = queryArg("ids")

	clauseFilter  = queryArg("filter")
	clauseGroupBy = queryArg("groupBy")
	clauseLimit   = queryArg("limit")
	clauseOffset  = queryArg("offset")
	clauseOrder   = queryArg("order")
)

Otherwise I don't mind a sub package but I think it should be an internal one if we don't plan on making those public.

Copy link
Member Author

@shahzadlone shahzadlone May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for my recommendation for the list of constants, my preferred solution would be to keep the constants 'here' but in the following form:

Where is here haha? like in the same file that I made? What names would you recommend with the sub-package approach? are you recommending two namespaces? clauses and types packages?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is where you have it. Same file.

If you want to use sub-packages, i would use internal/clauses and internal/types

Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved assuming the Property discussion will be resolved before merge

@shahzadlone shahzadlone force-pushed the lone/tools/add-goconst-linter branch from 0e68988 to a71aa71 Compare May 19, 2022 12:11
@source-devs

This comment was marked as off-topic.

@source-devs

This comment was marked as off-topic.

@shahzadlone shahzadlone added the action/no-benchmark Skips the action that runs the benchmark. label May 19, 2022
)

const (
Cid = string("cid")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: what's the difference between "cid" and string("cid")?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helping the compiler infer.

If we don't do either Cid = string("cid") or Cid string = "cid", i.e. I have Cid = "cid" lets say.

Then, the type is shown as const Cid untyped string rather than const Cid string

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change this to Cid string = "cid"? Otherwise it looks like you are converting a string to a string.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helping the compiler infer.

The Go compiler doesnt need help here, and dev readability should always trump anything compiler-help-related (maybe c++ templates have a bad rep. here?). The compiler is a tool to help the developer, not the other way around and our build times are really low.

Copy link
Member Author

@shahzadlone shahzadlone May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I personally don't care and do prefer the one that isn't Cid = string("cid") or Cid string = "cid". However I started doing this because @fredcarle made this suggestion when I only had key_1 = "/p/0/0/k1" instead of key_1 string = "/p/0/0/k1" earlier in this PR.

Not sure what the difference here is @fredcarle

image

Copy link
Member Author

@shahzadlone shahzadlone May 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I always prefer implicit typing (cant think of any exceptions atm). If the compiler struggles with this then there is a bug in in compiler IMO lol.

In light of what I posted above, there is no bug in the compiler for const cid = "cid" the actual type is not string type, it is actually untyped string, which is the defined behavior. So, would prefer const cid string = "cid" explicitly, to make it a string type.

Copy link
Member Author

@shahzadlone shahzadlone May 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover, for our iota constants we currently have them as untyped int which might be fine because otherwise we wouldn't be able to use them as the enum effect we want (for example cannot use CommitSelection as type SelectionType like we are using already)

We have this:

	ScanQuery = iota
	VersionedScanQuery

	NoneSelection = iota
	ObjectSelection
	CommitSelection

if we had something like:

	ScanQuery int = iota
	VersionedScanQuery

	NoneSelection int = iota
	ObjectSelection
	CommitSelection

Then we will not be able to do this:

query/graphql/parser/commit.go:57:2: cannot use types.CommitSelection (type int) as type types.SelectionType in return argu
query/graphql/parser/commit.go:84:3: cannot use types.CommitSelection (type int) as type types.SelectionType in field value
query/graphql/parser/mutation.go:107:2: cannot use types.ObjectSelection (type int) as type types.SelectionType in return a
query/graphql/parser/query.go:248:30: cannot use types.ObjectSelection (type int) as type types.SelectionType in argument t
query/graphql/parser/query.go:347:19: cannot use types.VersionedScanQuery (type int) as type types.SelectQueryType in assig
query/graphql/parser/query.go:349:19: cannot use types.ScanQuery (type int) as type types.SelectQueryType in assignment
query/graphql/parser/query.go:433:14: cannot use types.CommitSelection (type int) as type types.SelectionType in assignment

Copy link
Member Author

@shahzadlone shahzadlone May 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I have given it some more thought and would actually be in favor of having untyped string while using const. This would give us more freedom to compare of use constants with other types that aren't string (but their underlying type is string).

Consider this :

type a_string = string
type not_a_string string

const (
	aString       a_string     = "_str" // type: `string`
	typedString   string       = "_str" // type: `string`
	notString     not_a_string = "_str" // type: `not_a_string`
	untypedString              = "_str" // type: `untyped string`
)

func stringTest() {
	// cannot compare typedString == notString (mismatched types string and not_a_string)
	string_vs_notString := typedString == notString // Error

	untypedString_vs_notString := untypedString == notString

	untypedString_vs_string := untypedString == typedString
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) Cheers for posting all of that Shahzad! Really nice write up, and explains some of the stuff I saw when typing the Doc stuff too. Really had no idea this language feature existed in Go.

I think I also agree with you and prefer the untyped version too by default, and should only type it when we have good reason to lock it down (for example for context keys perhaps).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Appreciate the discussion @fredcarle @AndrewSisley

Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just one minor question, thanks for taking the time to sort this out (and decouple the packages)

@orpheuslummis
Copy link
Contributor

LGTM. Just one minor question, thanks for taking the time to sort this out (and decouple the packages)

It'd be nice to indicate the decoupling in the PR/commit title

@orpheuslummis
Copy link
Contributor

LGTM. Just one minor question, thanks for taking the time to sort this out (and decouple the packages)

It'd be nice to indicate the decoupling in the PR/commit title

If there is a followup PR dedicated to the 'decoupling', then it'd be fine to just detail it in the commit message in this one.

@shahzadlone shahzadlone force-pushed the lone/tools/add-goconst-linter branch from 34ec25a to 9c7771b Compare May 20, 2022 17:48
@shahzadlone shahzadlone force-pushed the lone/tools/add-goconst-linter branch from 9c7771b to efdf778 Compare May 20, 2022 17:55
@shahzadlone shahzadlone merged commit ec3334a into develop May 20, 2022
@shahzadlone shahzadlone deleted the lone/tools/add-goconst-linter branch May 20, 2022 18:03
shahzadlone added a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
- RELATED ISSUE(S):
Resolves sourcenetwork#403

- DESCRIPTION:
Enables the goconst linter and and resolves all it's errors.

This was one of the remaining linters we didn't have enabled from the list of recommended ones that were mentioned in the book 100 go mistakes and how to avoid them.

One side affect of this PR was that schema package was decoupled from using the parser package.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/no-benchmark Skips the action that runs the benchmark. code quality Related to improving code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lint: Enable the goconst linter
6 participants