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

Accessing a Dictionary containing Vectors results in String allocations on iOS. #1

Open
PrimaryFeather opened this issue Jun 29, 2017 · 15 comments

Comments

@PrimaryFeather
Copy link
Contributor

Problem Description

On iOS (only), assigning a property from a flash.utils.Dictionary, where the property type is a Vector of any non-primitive type, results in at least 3 hidden string allocations, according to Scout.

This was tested with the latest AIR Beta SDK (version 26.0.0 build 112), and several iOS devices using iOS 10.3.2. On Android and Desktop, there are no allocations.

Adobe Tracker Issue: https://tracker.adobe.com/#/view/AIR-4115729

Steps to Reproduce

The class StringAllocationIssue.as constitutes a minimal sample that showcases the problem by accessing a Dictionary once per frame, and StringAllocationIssue.flm shows the analysis of this application on an iPhone 6S. You'll see that once per frame, there are three String allocations; those do not happen on Android or Desktop.

Known Workarounds

When using an Array instead of a Vector, there are no allocations.

@hardcoremore
Copy link

@ajwfrost Andrew, this is also important one. Is there a hope for this to be fixed?

@ajwfrost
Copy link
Collaborator

ajwfrost commented Oct 8, 2019

Yes we can look into this one, I've added it to our internal tracker at AIR-256

@hardcoremore
Copy link

Awesome,

Thanks so much Andrew.

Regards,

Caslav

@hardcoremore
Copy link

Also this is happening for Vectors of non primitive type as well. It does not have to be Dictionary.

@jimmymjing
Copy link

I'm facing the same issue.

@ajwfrost
Copy link
Collaborator

So we've found the reason for these string allocations.. basically the AOT compilation needs to look up the traits of the vector of whatever object type is being referenced here, and it does this by creating the fully qualified name of the type and then doing an internal string-based query in the domain.

We're going to see if there's a different way that we can access the traits here that will avoid the string allocations; as a fallback option though, these strings should be being cached/reused so that they are created at most once for each vector type!

@PrimaryFeather
Copy link
Contributor Author

Thanks so much for looking into this, Andrew! It's great to finally know what's happening here – and caching that String seems like a sound solution to me.

@hardcoremore
Copy link

hardcoremore commented Feb 25, 2020

Awesome work Andrew!

So that is how much Adobe was lazy, at a minimum they could at least just use one string for each type but they were too lazy to even do that. Anyway this will save a lot of GC collection calls. Thanks again!

@hardcoremore
Copy link

Hi @ajwfrost,

Any news about this issue?

Regards,

Caslav

@ajwfrost
Copy link
Collaborator

@hardcoremore this is on our current list - we did start looking at it so should have an implementation in there soon..

@hardcoremore
Copy link

Awesome, thanks @ajwfrost.

@jimmymjing
Copy link

@ajwfrost @hardcoremore
Hello, I'm still facing this String allocation issue on iOS. Is there any news? thanks so much!

@hardcoremore
Copy link

@jimmymjing this was fixed I think. But I didn't test it. Do you see one string allocation per Vector/Dictionary or multiple?

@jimmymjing
Copy link

jimmymjing commented Sep 23, 2020

@hardcoremore I just read through your post on Starling's forum and I also thought it was fixed. but I'm seeing a lot of string allocation with DispatchEventWith() function call in scout.
Here's the screenshot: https://ibb.co/DKzCdWR

@ajwfrost
Copy link
Collaborator

ajwfrost commented Jul 7, 2021

Hi all - I just spotted this thread again, thought this had been closed...
So we did update the code so that the original issue is fixed: there will be a string allocation when the first vector type is generated but subsequent accesses should reuse the strings.

It sounds like there are other places where string allocations are happening though. Don't forget that anywhere you create a String object there will be an allocation, so events are quite big culprits for this. Internally the character memory that holds the string is handled fairly efficiently, so e.g. the character memory holding "enterFrame" will be set up once, but then each event that's created will create a new String object that refers to this.

I don't think that's the most efficient thing in the world - even the fact that every frame is sent a newly created enterFrame event seems a bit daft to me. So we can look a bit further into efficiency savings here: please let me know of any particular issues you're seeing where you think that string allocations should be unnecessary!

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants