-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
When using a Filter with lots of elements, get "Uncaught RangeError: Maximum call stack size exceeded" #1782
Comments
@mourner : I've been told this might be in your purview? |
This looks pretty fun, the filter system was not designed to handle few thousand rules in one place... Do you really have to filter this way, or could you add some single flag on the data side instead? |
I have this same error using high numbers of filters. Shown in an unrelated issue example #1785 (the gist will give the error at zoom level 2) |
It'd be very problematic to refactor our other code to use a more
simplistic filter on the Layer... essentially it would require generating
an order of magnitude more shapes... anything that could be done to make
the Filter more robust? It sounds like a needed feature...
|
I have this problem adding markers on a heat layer, and there was only 5 itens. |
@diogobif can you put up a minimal JSFiddle test case that reproduces the issue? |
I'm running more tests now, if it persists, I'll send you my code! |
@diogobif It looks like you're using Mapbox.js, not Mapbox GL JS, so your issue is unrelated to this one. |
@mourner I think I have a fix, but I'm not sure if it's in keeping with the codebase's general style, so please take a look and apply it if you feel it passes muster. Basically, I want to make it possible to specify the filter as a Function. Since this leads to cloning issues down the line, it actually needs to be passed as a String. And, of course, it can't use anything from the calling Scope. The change is quite simple, but is in https://github.com/mapbox/feature-filter: function compile(filter) {
if (typeof filter === "string") {return filter+'(p,t)';}
return operators[filter[0]].apply(filter, filter);
} Then, instead of specifying a Filter like so: var idFilter = ["in", "district_id"].concat(districtIds); One could optionally do the following: var idFilter = "function(properties,type) {return ["+districtIds.join()+"].indexOf(properties.district_id)>=0;}"; While I dislike passing eval()d Strings, this approach would allow for much more flexibility, and also solves the problem at hand. I've done some basic testing of the approach, and it appears to run in similar time, and cause no other problems. |
PS a possible change to avoid user-specified Functions as Strings: allow filter to be specified as Function, convert to String before cloning... however, this makes it somewhat less obvious that Scope needs to be obeyed. |
@peckjon no, functions are not serializable. We have to keep the style spec fully JSON-compliant. Could you set up a simple minimal JSFiddle test case that demonstrate the original issue (call stack overflow)? |
@mourner https://jsfiddle.net/cvmcj9nk/ (note the console log) If String-ified functions are abhorrent, this could also be solved by making the 'in' operation in feature-filter more efficient at https://github.com/mapbox/feature-filter/blob/master/index.js#L35 As of now, it ORs a set of equality checks instead of, for example, using .indexOf() on an Array. It is the size of that evaluated "(foo==bar)||..." String which causes the call stack exceeded error, at https://github.com/mapbox/feature-filter/blob/master/index.js#L77 |
…aximum call stack size exceeded" Fixes mapbox/mapbox-gl-js#1782
Fixes mapbox/mapbox-gl-js#1782 If too many elements (varies by environment, but appx 1-2k) are used for an 'in' filter, it will fail with "Uncaught RangeError: Maximum call stack size exceeded". This is because the logical comparison of many infix comarisons (eg "(p['foo']==='bar') || (p['foo']==='cat') || ...") becomes too long for the v8natives to handle.
Pending fix at mapbox/feature-filter#7 |
I'm attempting to render a Layer with a Filter statement containing a few thousand elements. Example:
If I omit the Filter statement, or decrease the size of districtIds to a few hundred elements, things work fine. But if I have a large number of elements in the Filter, this happens:
I've not had any luck finding a workaround... it appears to be a fairly low-level bug having to do with how/when the Filter function is compiled.
I can provide a (non-)working example if needed.
Thanks,
Jon Peck
jon@empowerengine.com
The text was updated successfully, but these errors were encountered: