Skip to content

Improve typed array sort #1040

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

Closed
wants to merge 5 commits into from
Closed

Improve typed array sort #1040

wants to merge 5 commits into from

Conversation

MaxGraey
Copy link
Member

@MaxGraey MaxGraey commented Jan 2, 2020

Fix #1039

@MaxGraey
Copy link
Member Author

MaxGraey commented Jan 2, 2020

@dcodeIO It's actually workaround which also has less retains. But I guess problem with RC in similar situations not solved in general case

@dcodeIO
Copy link
Member

dcodeIO commented Jan 2, 2020

Seems the related issue is #1039. Should probably fix the underlying problem, but wondering how that happens.

@MaxGraey MaxGraey changed the title Fix typed array sort Improve typed array sort Jan 3, 2020
Comment on lines -3385 to -3396
call $~lib/rt/pure/__retain
local.tee $1
call $~lib/typedarray/Int64Array#get:length
local.tee $2
i32.const 1
i32.le_s
if
local.get $1
call $~lib/rt/pure/__release
br $~lib/typedarray/SORT<~lib/typedarray/Float64Array,f64>|inlined.0
end
local.get $1
Copy link
Member Author

@MaxGraey MaxGraey Jan 3, 2020

Choose a reason for hiding this comment

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

@dcodeIO It seems this PR still has improvements after rebased from #1043, so I leave it opened. Also it add simple sort tests for Int32Array with 2 and 3 elements which also good to have to prevent similar regressions in future

i32.load
local.set $6
i32.const 2
global.set $~lib/argc
Copy link
Member Author

Choose a reason for hiding this comment

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

@dcodeIO could we avoid this somehow?

Copy link
Member

Choose a reason for hiding this comment

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

That's there because we can't tell whether we are calling a trampoline under the hood, so if we do, it needs to know how many args to fill. For instance:

function a(a: i32): i32 { return a; }
function b(a: i32, b?: i32 = 1) { return a + b; }
var c = someCond ? a : b;
c(2); // must indicate one arg is present so b|trampoline inserts b=1

@dcodeIO dcodeIO closed this in #1043 Jan 9, 2020
@MaxGraey MaxGraey deleted the fix-typed-array-sort branch January 9, 2020 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Orphaned Decrement Error after sorting a TypedArray
2 participants