-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Performance issues with nested PacketField
s
#4705
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
Comments
Possibly related to #3894? |
Analysis Let N the number of packet fields at a given stage. As far as I've noticed, this is due to useless copies of packets during Let K the factor of time lost induced by these useless instantiations. |
Successfully fixed in a Scapy wrapper. I'll provide a PR soon to propose the integration of it directly in Scapy implementation. Notes:
|
Thanks for the report ! And thank you for the future PR. |
Version used for reporting of secdev#4705.
…4706, secdev#4707) - secdev#4705: Performance issues with nested `PacketField`s: - Cache saved in `Packet.self_build()`. - `Packet`s marked as explicit systematically in `Packet.build()` to avoid a useless clone in `do_build()`. - `Packet.do_init_cached_fields()` optimized: - `init_fields` parameter added to `Packet.init_fields()` and `do_init_cached_fields()`. - Misc: `do_init_cached_fields()` fixed for list field copies. - `Packet.prepare_cached_fields()` optimized: - Default fields not copied anymore. - `Packet.copy()` and `clone_with()` optimized with `_fast_copy()`: - Avoid instantiating *ref fields* with default instantiation. - `Packet.copy_fields_dict()` optimized with new `use_fields_already_set` parameter and reworked as an inner method to work directly on the `clone` instance. - Misc: `_T` variable type at the module level made local and renamed as `_VarDictFieldType` in `_fast_copy()`. - `Packet.setfieldval()` optimized: - New value discarded if unchanged.: - `_PacketField.m2i()` optimized: - Avoid useless copies of fields with default instance. - Then `dissect()` is used on it. - secdev#4707: [enhancement] Enable clear_cache() to spread upward in the packet tree: - `Packet.clear_cache()` reworked. - secdev#4706: Force cache reset as soon as the payload or a packet field is modified: - `Packet.clear_cache()` (reworked as per secdev#4707) called in `setfieldval()`, `delfieldval()`, `add_payload()` and `remove_payload()`. - `Packet.raw_packet_cache_fields` now useless, thus removed. - Same for `Packet._raw_packet_cache_field_value()`. - `Packet.self_build()` simplified by the way. - `Packet.no_cache` flag added to avoid setting `raw_packet_cache` when specified, used in `Packet.self_build()` and `do_dissect()`.
Useless now that `Packet.init_fields()` has a `for_dissect_only` parameter.
- Set step numbers. - Clarify max times. - Use regular parsing through instantiation in step 014.
- Test configurations extracted as global constants. - Base `TestPacket` class added. Made `M`, `I` and `F` inherit from it. - Max time computed from expected number of operations. - Default instantiations ran once (not twice anymore). - Serialization test cases added to highlight cache improvements.
…4706, secdev#4707) - secdev#4705: Performance issues with nested `PacketField`s: - Cache saved in `Packet.self_build()`. - `Packet`s marked as explicit systematically in `Packet.build()` to avoid a useless clone in `do_build()`. - `Packet.do_init_cached_fields()` optimized: - `init_fields` parameter added to `Packet.init_fields()` and `do_init_cached_fields()`. - Misc: `do_init_cached_fields()` fixed for list field copies. - `Packet.prepare_cached_fields()` optimized: - Default fields not copied anymore. - `Packet.copy()` and `clone_with()` optimized with `_fast_copy()`: - Avoid instantiating *ref fields* with default instantiation. - `Packet.copy_fields_dict()` optimized with new `use_fields_already_set` parameter and reworked as an inner method to work directly on the `clone` instance. - Misc: `_T` variable type at the module level made local and renamed as `_VarDictFieldType` in `_fast_copy()`. - `Packet.setfieldval()` optimized: - New value discarded if unchanged.: - `_PacketField.m2i()` optimized: - Avoid useless copies of fields with default instance. - Then `dissect()` is used on it. - secdev#4707: [enhancement] Enable clear_cache() to spread upward in the packet tree: - `Packet.clear_cache()` reworked. - secdev#4706: Force cache reset as soon as the payload or a packet field is modified: - `Packet.clear_cache()` (reworked as per secdev#4707) called in `setfieldval()`, `delfieldval()`, `add_payload()` and `remove_payload()`. - `Packet.raw_packet_cache_fields` now useless, thus removed. - Same for `Packet._raw_packet_cache_field_value()`. - `Packet.self_build()` simplified by the way. - `Packet.no_cache` flag added to avoid setting `raw_packet_cache` when specified, used in `Packet.self_build()` and `do_dissect()`.
Useless now that `Packet.init_fields()` has a `for_dissect_only` parameter.
Brief description
When
PacketField
s are nested on several stages,Scapy races exponential performance issues.
Scapy version
2.6.1
Python version
3.8.6
Operating system
Windows
Additional environment information
No response
How to reproduce
The following .uts test demonstrates the issue:
Actual result
No response
Expected result
No response
Related resources
No response
The text was updated successfully, but these errors were encountered: