X
Нажмите здесь, чтобы перейти на мобильную версию сайта.

Форум поддержки

Large PAC file doesn't seem to work properly

Размещено

I have three PAC files.

First, https://vindicar.name/proxy.pac (under 1KB)

Second, https://vindicar.name/proxy2.pac (1.9MB)

Third, https://vindicar.name/proxy3.pac (519KB)

They are almost identical in structure, performing a search through a list of IPs to determine is a proxy needs to be used. The only difference is that first has a tiny list of ips. the second has actual list of IPs, and the third has a significantly reduced list. The largest one was generated by a script, so I don't expect any sneaky syntax errors in there.

Smaller PAC files work just fine, directing requests through a private proxy. I tested it by adding whatismyipaddress.com to blacklisted domains and comparing its output to another "get my ip" site. The largest PAC file seems to have no effect whatsoever, with Firefox falling back to direct connection.

Is there any size and/or execution time restriction on PAC files?

Appendix 1: General structure of PAC files above:

 function FindProxyForURL(url, host) {
   var ipblacklist = [
   // List of IPs goes here, in decimal notation:
   // "127.0.0.1",
   // "192.168.0.1",
   // and so on
   ];
   var domainblacklist = [
   'privoxy.org',
   'whatismyipaddress.com',
   ];
 
   function endsWith(str, suffix) {
     return str.indexOf(suffix, str.length - suffix.length) !== -1;
   }
   var blocked = false;
   for (var i=0; !blocked && (i<domainblacklist.length); i++)
     blocked = blocked || ((host == domainblacklist[i]) || endsWith(host, '.'+domainblacklist[i]));
   if (blocked || (ipblacklist.indexOf(dnsResolve(host)) != -1))
     // That proxy is accessible via my VPN, you will have to substitute your own for testing
     return "PROXY 10.42.0.1:8118; SOCKS5 10.42.0.1:8118";
   else
     return "DIRECT";
 }
I have three PAC files. First, https://vindicar.name/proxy.pac (under 1KB) Second, https://vindicar.name/proxy2.pac (1.9MB) Third, https://vindicar.name/proxy3.pac (519KB) They are almost identical in structure, performing a search through a list of IPs to determine is a proxy needs to be used. The only difference is that first has a tiny list of ips. the second has actual list of IPs, and the third has a significantly reduced list. The largest one was generated by a script, so I don't expect any sneaky syntax errors in there. Smaller PAC files work just fine, directing requests through a private proxy. I tested it by adding whatismyipaddress.com to blacklisted domains and comparing its output to another "get my ip" site. The largest PAC file seems to have no effect whatsoever, with Firefox falling back to direct connection. Is there any size and/or execution time restriction on PAC files? Appendix 1: General structure of PAC files above: function FindProxyForURL(url, host) { var ipblacklist = [ // List of IPs goes here, in decimal notation: // "127.0.0.1", // "192.168.0.1", // and so on ]; var domainblacklist = [ 'privoxy.org', 'whatismyipaddress.com', ]; function endsWith(str, suffix) { return str.indexOf(suffix, str.length - suffix.length) !== -1; } var blocked = false; for (var i=0; !blocked && (i&lt;domainblacklist.length); i++) blocked = blocked || ((host == domainblacklist[i]) || endsWith(host, '.'+domainblacklist[i])); if (blocked || (ipblacklist.indexOf(dnsResolve(host)) != -1)) // That proxy is accessible via my VPN, you will have to substitute your own for testing return "PROXY 10.42.0.1:8118; SOCKS5 10.42.0.1:8118"; else return "DIRECT"; }

Изменено Vindicar

Выбранное решение

Some thoughts: I’m not too skilled in this area, but it seems the number of "possible" IPs used for the variable in your rather large script causes the issue at some point. Things work fine for me when the last IP is on line 91136, but no longer for 91137 or more. It’s not clear to me whether this limitation is due to the number of possible IPs for the variable itself (I don’t think so), the dnsResolve(host) function or other parts of the script (or even the pac file’s size), but one of the latter seems more obvious. A quick thought: can you split the IP list into 2 or more sections and hence use 2 or more variables?

Do note that you will probably see the "PAC Execution Error: uncaught exception: out of memory []" error when opening the Browser Console (Ctrl+Shift+J), which even happens when the IP list does not exceed the value above. This presumably slows down the browser too and moreover, makes the script unreliable. Bugs have been reported for the memory issue, one was solved by increasing the heap size to 4 MB. Therefore any restriction may not be due to a certain amount of IPs or other value or function but simply the memory it consumes, so splitting the list may not work either. All together, I think people more familiar with pac files will tell you the file is set up in a way it shouldn’t, like here.

You may be familiar with this page on MDN - note the warning about carefully considering the use of the dnsResolve(host) function. Findproxyforurl.com is a nice reference too. In order to debug and optimize the script, there may be a way to let it throw an alert to indicate the lookup "error", or rather, memory consumption. I assume you thought of blocking subnets rather than separate IPs?

Hope this helps a bit.

Прочитайте этот ответ в контексте 1

Дополнительные сведения о системе

Приложение

  • Firefox 60.0.2
  • User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0
  • URL поддержки: https://support.mozilla.org/1/firefox/60.0.2/WINNT/ru/

Расширения

  • FB2 Reader 0.31 (fb2reader@clear.com.ua)
  • Greasemonkey 4.1 ({e4a8a97b-f2ed-450b-b12d-ee082ba24781})
  • NoScript 10.1.8.2 ({73a6fe31-595d-460b-a920-fcc0f8843232})
  • uBlock Origin 1.16.8 (uBlock0@raymondhill.net)
  • App Tab Initializer 0.2.1-signed.1-signed ({0e91bc50-5f71-11e0-80e3-0800200c9a66}) (Неактивно)
  • Classic Theme Restorer 1.7.6 (ClassicThemeRestorer@ArisT2Noia4dev) (Неактивно)
  • XML Search Engines Exporter/Importer 0.4 (xseei@nohamelin) (Неактивно)

Javascript

  • incrementalGCEnabled: True

Графика

  • adapterDescription: NVIDIA GeForce GTX 1050 Ti
  • adapterDescription2:
  • adapterDeviceID: 0x1c82
  • adapterDeviceID2:
  • adapterDrivers: C:\WINDOWS\System32\DriverStore\FileRepository\nv_ref_pubwu.inf_amd64_2e7fa54192fe16d0\nvldumdx.dll,C:\WINDOWS\System32\DriverStore\FileRepository\nv_ref_pubwu.inf_amd64_2e7fa54192fe16d0\nvldumdx.dll,C:\WINDOWS\System32\DriverStore\FileRepository\nv_ref_pubwu.inf_amd64_2e7fa54192fe16d0\nvldumdx.dll,C:\WINDOWS\System32\DriverStore\FileRepository\nv_ref_pubwu.inf_amd64_2e7fa54192fe16d0\nvldumdx.dll C:\WINDOWS\System32\DriverStore\FileRepository\nv_ref_pubwu.inf_amd64_2e7fa54192fe16d0\nvldumd.dll,C:\WINDOWS\System32\DriverStore\FileRepository\nv_ref_pubwu.inf_amd64_2e7fa54192fe16d0\nvldumd.dll,C:\WINDOWS\System32\DriverStore\FileRepository\nv_ref_pubwu.inf_amd64_2e7fa54192fe16d0\nvldumd.dll,C:\WINDOWS\System32\DriverStore\FileRepository\nv_ref_pubwu.inf_amd64_2e7fa54192fe16d0\nvldumd.dll
  • adapterDrivers2:
  • adapterRAM: 4096
  • adapterRAM2:
  • adapterSubsysID: 33511462
  • adapterSubsysID2:
  • adapterVendorID: 0x10de
  • adapterVendorID2:
  • crashGuards: [{u'prefName': u'gfx.crash-guard.status.d3d9video', u'type': u'd3d9video'}]
  • direct2DEnabled: True
  • directWriteEnabled: True
  • directWriteVersion: 10.0.17134.1
  • driverDate: 10-27-2017
  • driverDate2:
  • driverVersion: 23.21.13.8813
  • driverVersion2:
  • featureLog: {u'fallbacks': [], u'features': [{u'status': u'available', u'description': u'Compositing', u'log': [{u'status': u'available', u'type': u'default'}], u'name': u'HW_COMPOSITING'}, {u'status': u'available', u'description': u'Direct3D11 Compositing', u'log': [{u'status': u'available', u'type': u'default'}], u'name': u'D3D11_COMPOSITING'}, {u'status': u'available', u'description': u'Direct2D', u'log': [{u'status': u'available', u'type': u'default'}], u'name': u'DIRECT2D'}, {u'status': u'available', u'description': u'Direct3D11 hardware ANGLE', u'log': [{u'status': u'available', u'type': u'default'}], u'name': u'D3D11_HW_ANGLE'}, {u'status': u'available', u'description': u'GPU Process', u'log': [{u'status': u'available', u'type': u'default'}], u'name': u'GPU_PROCESS'}, {u'status': u'unavailable', u'description': u'WebRender', u'log': [{u'status': u'opt-in', u'message': u'WebRender is an opt-in feature', u'type': u'default'}, {u'status': u'unavailable', u'message': u"Build doesn't include WebRender", u'type': u'runtime'}], u'name': u'WEBRENDER'}, {u'status': u'available', u'description': u'Off Main Thread Painting', u'log': [{u'status': u'available', u'type': u'default'}], u'name': u'OMTP'}, {u'status': u'available', u'description': u'Advanced Layers', u'log': [{u'status': u'available', u'type': u'default'}], u'name': u'ADVANCED_LAYERS'}]}
  • info: {u'AzureContentBackend (UI Process)': u'skia', u'AzureCanvasBackend (UI Process)': u'skia', u'ApzWheelInput': 1, u'ApzDragInput': 1, u'ApzKeyboardInput': 1, u'AzureFallbackCanvasBackend (UI Process)': u'cairo', u'ApzAutoscrollInput': 1, u'AzureCanvasAccelerated': 0, u'AzureCanvasBackend': u'Direct2D 1.1', u'AzureContentBackend': u'Direct2D 1.1'}
  • isGPU2Active: False
  • numAcceleratedWindows: 2
  • numTotalWindows: 2
  • offMainThreadPaintEnabled: True
  • offMainThreadPaintWorkerCount: 0
  • usesTiling: False
  • webgl1DriverExtensions: GL_ANGLE_client_arrays GL_ANGLE_depth_texture GL_ANGLE_framebuffer_blit GL_ANGLE_framebuffer_multisample GL_ANGLE_instanced_arrays GL_ANGLE_lossy_etc_decode GL_ANGLE_pack_reverse_row_order GL_ANGLE_program_cache_control GL_ANGLE_request_extension GL_ANGLE_robust_client_memory GL_ANGLE_texture_compression_dxt3 GL_ANGLE_texture_compression_dxt5 GL_ANGLE_texture_usage GL_ANGLE_translated_shader_source GL_CHROMIUM_bind_generates_resource GL_CHROMIUM_bind_uniform_location GL_CHROMIUM_color_buffer_float_rgb GL_CHROMIUM_color_buffer_float_rgba GL_CHROMIUM_copy_compressed_texture GL_CHROMIUM_copy_texture GL_CHROMIUM_sync_query GL_EXT_blend_minmax GL_EXT_color_buffer_half_float GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_disjoint_timer_query GL_EXT_draw_buffers GL_EXT_frag_depth GL_EXT_map_buffer_range GL_EXT_occlusion_query_boolean GL_EXT_read_format_bgra GL_EXT_robustness GL_EXT_sRGB GL_EXT_shader_texture_lod GL_EXT_texture_compression_dxt1 GL_EXT_texture_compression_s3tc_srgb GL_EXT_texture_filter_anisotropic GL_EXT_texture_format_BGRA8888 GL_EXT_texture_rg GL_EXT_texture_storage GL_EXT_unpack_subimage GL_KHR_debug GL_NV_EGL_stream_consumer_external GL_NV_fence GL_NV_pack_subimage GL_NV_pixel_buffer_object GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth32 GL_OES_element_index_uint GL_OES_get_program_binary GL_OES_mapbuffer GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_surfaceless_context GL_OES_texture_float GL_OES_texture_float_linear GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_texture_npot GL_OES_vertex_array_object
  • webgl1Extensions: ANGLE_instanced_arrays EXT_blend_minmax EXT_color_buffer_half_float EXT_frag_depth EXT_sRGB EXT_shader_texture_lod EXT_texture_filter_anisotropic EXT_disjoint_timer_query OES_element_index_uint OES_standard_derivatives OES_texture_float OES_texture_float_linear OES_texture_half_float OES_texture_half_float_linear OES_vertex_array_object WEBGL_color_buffer_float WEBGL_compressed_texture_s3tc WEBGL_compressed_texture_s3tc_srgb WEBGL_debug_renderer_info WEBGL_debug_shaders WEBGL_depth_texture WEBGL_draw_buffers WEBGL_lose_context
  • webgl1Renderer: Google Inc. -- ANGLE (NVIDIA GeForce GTX 1050 Ti Direct3D11 vs_5_0 ps_5_0)
  • webgl1Version: OpenGL ES 2.0 (ANGLE 2.1.0.7edc21933ef1)
  • webgl1WSIInfo: EGL_VENDOR: Google Inc. (adapter LUID: 0000000000009578) EGL_VERSION: 1.4 (ANGLE 2.1.0.7edc21933ef1) EGL_EXTENSIONS: EGL_EXT_create_context_robustness EGL_ANGLE_d3d_share_handle_client_buffer EGL_ANGLE_d3d_texture_client_buffer EGL_ANGLE_surface_d3d_texture_2d_share_handle EGL_ANGLE_query_surface_pointer EGL_ANGLE_window_fixed_size EGL_ANGLE_keyed_mutex EGL_ANGLE_surface_orientation EGL_ANGLE_direct_composition EGL_NV_post_sub_buffer EGL_KHR_create_context EGL_EXT_device_query EGL_KHR_image EGL_KHR_image_base EGL_KHR_gl_texture_2D_image EGL_KHR_gl_texture_cubemap_image EGL_KHR_gl_renderbuffer_image EGL_KHR_get_all_proc_addresses EGL_KHR_stream EGL_KHR_stream_consumer_gltexture EGL_NV_stream_consumer_gltexture_yuv EGL_ANGLE_flexible_surface_compatibility EGL_ANGLE_stream_producer_d3d_texture EGL_ANGLE_create_context_webgl_compatibility EGL_CHROMIUM_create_context_bind_generates_resource EGL_CHROMIUM_sync_control EGL_EXT_pixel_format_float EGL_KHR_surfaceless_context EGL_ANGLE_display_texture_share_group EGL_ANGLE_create_context_client_arrays EGL_ANGLE_program_cache_control EGL_ANGLE_robust_resource_initialization EGL_EXTENSIONS(nullptr): EGL_EXT_client_extensions EGL_EXT_platform_base EGL_EXT_platform_device EGL_ANGLE_platform_angle EGL_ANGLE_platform_angle_d3d EGL_ANGLE_device_creation EGL_ANGLE_device_creation_d3d11 EGL_ANGLE_experimental_present_path EGL_KHR_client_get_all_proc_addresses
  • webgl2DriverExtensions: GL_ANGLE_client_arrays GL_ANGLE_depth_texture GL_ANGLE_framebuffer_blit GL_ANGLE_framebuffer_multisample GL_ANGLE_instanced_arrays GL_ANGLE_lossy_etc_decode GL_ANGLE_multiview GL_ANGLE_pack_reverse_row_order GL_ANGLE_program_cache_control GL_ANGLE_request_extension GL_ANGLE_robust_client_memory GL_ANGLE_texture_compression_dxt3 GL_ANGLE_texture_compression_dxt5 GL_ANGLE_texture_usage GL_ANGLE_translated_shader_source GL_CHROMIUM_bind_generates_resource GL_CHROMIUM_bind_uniform_location GL_CHROMIUM_color_buffer_float_rgb GL_CHROMIUM_color_buffer_float_rgba GL_CHROMIUM_copy_compressed_texture GL_CHROMIUM_copy_texture GL_CHROMIUM_sync_query GL_EXT_blend_minmax GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_disjoint_timer_query GL_EXT_draw_buffers GL_EXT_frag_depth GL_EXT_map_buffer_range GL_EXT_occlusion_query_boolean GL_EXT_read_format_bgra GL_EXT_robustness GL_EXT_sRGB GL_EXT_shader_texture_lod GL_EXT_texture_compression_dxt1 GL_EXT_texture_compression_s3tc_srgb GL_EXT_texture_filter_anisotropic GL_EXT_texture_format_BGRA8888 GL_EXT_texture_norm16 GL_EXT_texture_rg GL_EXT_texture_storage GL_EXT_unpack_subimage GL_KHR_debug GL_NV_EGL_stream_consumer_external GL_NV_fence GL_NV_pack_subimage GL_NV_pixel_buffer_object GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_EGL_image_external_essl3 GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth32 GL_OES_element_index_uint GL_OES_get_program_binary GL_OES_mapbuffer GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_surfaceless_context GL_OES_texture_float GL_OES_texture_float_linear GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_texture_npot GL_OES_vertex_array_object
  • webgl2Extensions: EXT_color_buffer_float EXT_texture_filter_anisotropic EXT_disjoint_timer_query OES_texture_float_linear WEBGL_compressed_texture_s3tc WEBGL_compressed_texture_s3tc_srgb WEBGL_debug_renderer_info WEBGL_debug_shaders WEBGL_lose_context
  • webgl2Renderer: Google Inc. -- ANGLE (NVIDIA GeForce GTX 1050 Ti Direct3D11 vs_5_0 ps_5_0)
  • webgl2Version: OpenGL ES 3.0 (ANGLE 2.1.0.7edc21933ef1)
  • webgl2WSIInfo: EGL_VENDOR: Google Inc. (adapter LUID: 0000000000009578) EGL_VERSION: 1.4 (ANGLE 2.1.0.7edc21933ef1) EGL_EXTENSIONS: EGL_EXT_create_context_robustness EGL_ANGLE_d3d_share_handle_client_buffer EGL_ANGLE_d3d_texture_client_buffer EGL_ANGLE_surface_d3d_texture_2d_share_handle EGL_ANGLE_query_surface_pointer EGL_ANGLE_window_fixed_size EGL_ANGLE_keyed_mutex EGL_ANGLE_surface_orientation EGL_ANGLE_direct_composition EGL_NV_post_sub_buffer EGL_KHR_create_context EGL_EXT_device_query EGL_KHR_image EGL_KHR_image_base EGL_KHR_gl_texture_2D_image EGL_KHR_gl_texture_cubemap_image EGL_KHR_gl_renderbuffer_image EGL_KHR_get_all_proc_addresses EGL_KHR_stream EGL_KHR_stream_consumer_gltexture EGL_NV_stream_consumer_gltexture_yuv EGL_ANGLE_flexible_surface_compatibility EGL_ANGLE_stream_producer_d3d_texture EGL_ANGLE_create_context_webgl_compatibility EGL_CHROMIUM_create_context_bind_generates_resource EGL_CHROMIUM_sync_control EGL_EXT_pixel_format_float EGL_KHR_surfaceless_context EGL_ANGLE_display_texture_share_group EGL_ANGLE_create_context_client_arrays EGL_ANGLE_program_cache_control EGL_ANGLE_robust_resource_initialization EGL_EXTENSIONS(nullptr): EGL_EXT_client_extensions EGL_EXT_platform_base EGL_EXT_platform_device EGL_ANGLE_platform_angle EGL_ANGLE_platform_angle_d3d EGL_ANGLE_device_creation EGL_ANGLE_device_creation_d3d11 EGL_ANGLE_experimental_present_path EGL_KHR_client_get_all_proc_addresses
  • windowLayerManagerRemote: True
  • windowLayerManagerType: Direct3D 11
  • windowUsingAdvancedLayers: True

Изменённые настройки

Разное

  • User JS: Нет
  • Доступность: Нет
cor-el
  • Top 10 Contributor
  • Moderator
17000 решений 153506 ответов
Размещено
Try to ask advice at the Stack Overflow forum site. *http://stackoverflow.com/questions/ *https://support.mozilla.org/en-US/kb/where-go-developer-support
Tonnes
  • Locale Leader
246 решений 1454 ответов
Размещено

Выбранное решение

Some thoughts: I’m not too skilled in this area, but it seems the number of "possible" IPs used for the variable in your rather large script causes the issue at some point. Things work fine for me when the last IP is on line 91136, but no longer for 91137 or more. It’s not clear to me whether this limitation is due to the number of possible IPs for the variable itself (I don’t think so), the dnsResolve(host) function or other parts of the script (or even the pac file’s size), but one of the latter seems more obvious. A quick thought: can you split the IP list into 2 or more sections and hence use 2 or more variables?

Do note that you will probably see the "PAC Execution Error: uncaught exception: out of memory []" error when opening the Browser Console (Ctrl+Shift+J), which even happens when the IP list does not exceed the value above. This presumably slows down the browser too and moreover, makes the script unreliable. Bugs have been reported for the memory issue, one was solved by increasing the heap size to 4 MB. Therefore any restriction may not be due to a certain amount of IPs or other value or function but simply the memory it consumes, so splitting the list may not work either. All together, I think people more familiar with pac files will tell you the file is set up in a way it shouldn’t, like here.

You may be familiar with this page on MDN - note the warning about carefully considering the use of the dnsResolve(host) function. Findproxyforurl.com is a nice reference too. In order to debug and optimize the script, there may be a way to let it throw an alert to indicate the lookup "error", or rather, memory consumption. I assume you thought of blocking subnets rather than separate IPs?

Hope this helps a bit.

Some thoughts: I’m not too skilled in this area, but it seems the number of "possible" IPs used for the variable in your rather large script causes the issue at some point. Things work fine for me when the last IP is on line 91136, but no longer for 91137 or more. It’s not clear to me whether this limitation is due to the number of possible IPs for the variable itself (I don’t think so), the dnsResolve(host) function or other parts of the script (or even the pac file’s size), but one of the latter seems more obvious. A quick thought: can you split the IP list into 2 or more sections and hence use 2 or more variables? Do note that you will probably see the ''"PAC Execution Error: uncaught exception: out of memory []"'' error when opening the Browser Console (Ctrl+Shift+J), which even happens when the IP list does not exceed the value above. This presumably slows down the browser too and moreover, makes the script unreliable. Bugs have been reported for the memory issue, one was solved by increasing the heap size to 4 MB. Therefore any restriction may not be due to a certain amount of IPs or other value or function but simply the memory it consumes, so splitting the list may not work either. All together, I think people more familiar with pac files will tell you the file is set up in a way it shouldn’t, like [https://forum.palemoon.org/viewtopic.php?t=15424 here]. You may be familiar with [https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_(PAC)_file this page on MDN] - note the warning about carefully considering the use of the dnsResolve(host) function. [http://findproxyforurl.com Findproxyforurl.com] is a nice reference too. In order to debug and optimize the script, there may be a way to let it throw an alert to indicate the lookup "error", or rather, memory consumption. I assume you thought of blocking subnets rather than separate IPs? Hope this helps a bit.
Размещено

Задавший вопрос

First of all, thank you for your detailed and generally useful response.

Tonnes said

Do note that you will probably see the "PAC Execution Error: uncaught exception: out of memory []" error when opening the Browser Console (Ctrl+Shift+J), which even happens when the IP list does not exceed the value above.

I don't see this message in JS console. I have "Continuous logs" checkbox ticked, so it doesn't get cleared, but I only see messages generated by the site itself, and nothing PAC-related.

Tonnes said

You may be familiar with this page on MDN - note the warning about carefully considering the use of the dnsResolve(host) function.

If you check the code I listed, you will see that dnsResolve(host) gets called at most once - as a parameter to indexOf() method, rather than once per IP listed. That only happens if domains didn't match, so if I open whatismyipaddress.com, JS engine should optimize the call to indexOf() away, because blocked variable will have value of true already.

As far as I'm aware, in JS x = a || b should operate the same as if (a) x = true; else x = b;

Tonnes said

Some thoughts: I’m not too skilled in this area, but it seems the number of "possible" IPs used for the variable in your rather large script causes the issue at some point. Things work fine for me when the last IP is on line 91136, but no longer for 91137 or more. It’s not clear to me whether this limitation is due to the number of possible IPs for the variable itself (I don’t think so), the dnsResolve(host) function or other parts of the script (or even the pac file’s size), but one of the latter seems more obvious. A quick thought: can you split the IP list into 2 or more sections and hence use 2 or more variables?

The IP list comes from an external source. I changed the way IPs are encoded, transforming them into hexadecimal notation (e.g. 0x7F000001 for "127.0.0.1") and then using convert_addr() to do the same to IP of the target host.

This trick reduced filesize from 1.9MB down to 1.1MB, and PAC file started working again. I assume it's because storing and searching 100k+ integers is much easier than doing the same to 100k+ strings, even if there is not that much difference in terms of storage.

As I said, IP list comes from an external source, so if it keeps growing, my current solution will stop working. In that case I will have to merge IPs into subnets, and that's a non-trivial task if you want to do it sparingly and with as little "overhead" (IPs that weren't on the original list) as possible.

First of all, thank you for your detailed and generally useful response. ''Tonnes [[#answer-1121465|said]]'' <blockquote> Do note that you will probably see the ''"PAC Execution Error: uncaught exception: out of memory []"'' error when opening the Browser Console (Ctrl+Shift+J), which even happens when the IP list does not exceed the value above. </blockquote> I don't see this message in JS console. I have "Continuous logs" checkbox ticked, so it doesn't get cleared, but I only see messages generated by the site itself, and nothing PAC-related. ''Tonnes [[#answer-1121465|said]]'' <blockquote> You may be familiar with [https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_(PAC)_file this page on MDN] - note the warning about carefully considering the use of the dnsResolve(host) function. </blockquote> If you check the code I listed, you will see that dnsResolve(host) gets called at most once - as a parameter to indexOf() method, rather than once per IP listed. That only happens if domains didn't match, so if I open whatismyipaddress.com, JS engine should optimize the call to indexOf() away, because blocked variable will have value of true already. As far as I'm aware, in JS x = a || b should operate the same as if (a) x = true; else x = b; ''Tonnes [[#answer-1121465|said]]'' <blockquote> Some thoughts: I’m not too skilled in this area, but it seems the number of "possible" IPs used for the variable in your rather large script causes the issue at some point. Things work fine for me when the last IP is on line 91136, but no longer for 91137 or more. It’s not clear to me whether this limitation is due to the number of possible IPs for the variable itself (I don’t think so), the dnsResolve(host) function or other parts of the script (or even the pac file’s size), but one of the latter seems more obvious. A quick thought: can you split the IP list into 2 or more sections and hence use 2 or more variables? </blockquote> The IP list comes from an external source. I changed the way IPs are encoded, transforming them into hexadecimal notation (e.g. 0x7F000001 for "127.0.0.1") and then using [https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_(PAC)_file#convert_addr() convert_addr()] to do the same to IP of the target host. This trick reduced filesize from 1.9MB down to 1.1MB, and PAC file started working again. I assume it's because storing and searching 100k+ integers is much easier than doing the same to 100k+ strings, even if there is not that much difference in terms of storage. As I said, IP list comes from an external source, so if it keeps growing, my current solution will stop working. In that case I will have to merge IPs into subnets, and that's a non-trivial task if you want to do it sparingly and with as little "overhead" (IPs that weren't on the original list) as possible.

Изменено Vindicar

Tonnes
  • Locale Leader
246 решений 1454 ответов
Размещено

Thanks for the feedback, good you solved it for now. I won’t go into details about the function or coding itself - you’ll probably do a better job in that than me. ;)

Vindicar said

I don't see this message in JS console. I have "Continuous logs" checkbox ticked, so it doesn't get cleared, but I only see messages generated by the site itself, and nothing PAC-related.

Make sure to check the Browser Console, not the Web Console, as you will only see the pac file warning there, along with a loading message and perhaps others. It may be good to watch for the error and use it as an indication for optimizing the script now or when it gets too large.

If it helps: the warning does not display for me when the last IP is on line 90900, but does for 91000. As this is close to the 91136 mentioned earlier, I assume the memory issue is therefor related / the cause.

Thanks for the feedback, good you solved it for now. I won’t go into details about the function or coding itself - you’ll probably do a better job in that than me. ;) ''Vindicar [[#answer-1121497|said]]'' <blockquote> I don't see this message in JS console. I have "Continuous logs" checkbox ticked, so it doesn't get cleared, but I only see messages generated by the site itself, and nothing PAC-related. </blockquote> Make sure to check the Browser Console, not the Web Console, as you will only see the pac file warning there, along with a loading message and perhaps others. It may be good to watch for the error and use it as an indication for optimizing the script now or when it gets too large. If it helps: the warning does not display for me when the last IP is on line 90900, but does for 91000. As this is close to the 91136 mentioned earlier, I assume the memory issue is therefor related / the cause.